Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Left/Right/None/Nil implicit schemas #279

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

vigoo
Copy link
Contributor

@vigoo vigoo commented Jun 6, 2022

Currently we have implicit schemas for

  • Left and Right
  • None
  • Nil

and these schemas are not (necessarily) compatible with the schema of Either, Option and List. This leads to serialization errors in places where the schema is captured for polymorphic types such as in zio-flow:

zio/zio-flow#191

In this example if some zio-flow function is called with Nil the implicit Schema.nil was used for serialization but that was later assumed to be a List[A] and deserialization of that raw value fails.

Previously I made left and right schemas compatible with the either schema. An alternative solution to the problem would be to try doing the same with none and nil but I felt like it's more correct to just get rid of these implicits and force the users (of zio-schema) to know exactly what type they need schema for.

This means we can no longer get an implicit schema for Nil without having an implicit schema for a given A that would be the element type - but I think this is a valid assumption.

In polymorphic cases like the linked one, replacing Nil with List.empty[A] for example makes the compiler able to infer the proper types and find the implicit which I think is a good compromise.

I removed left and right too just to make the approach the same for all of these.

@vigoo vigoo requested a review from a team as a code owner June 6, 2022 07:50
@jdegoes jdegoes merged commit f3623b3 into zio:zio2 Jun 6, 2022
@vigoo vigoo deleted the remove-subclass-implicits branch June 6, 2022 08:20
jdegoes added a commit that referenced this pull request Aug 19, 2022
* Support ZIO 2.x (#149)

* Run scalafix ZIO 2 migration

* Get core project compiling

* Get Optics to compile and pass tests

* Get protobuf to compile and pass tests

* Run `sbt prepare`

* Remove unused reference to zio-nio in BuildHelper.scala

* Update to ZIO 2.0.0-RC1

* Update zio-schema-json and examples to ZIO 2

* Update dependency ch.epfl.scala:sbt-scalafix to v0.9.33 (#98)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Capture annotations on Enums and all cases (#167)

* Capture annotations on Enums and all cases

* Linting

* Update dependency com.github.ghik:silencer-lib to v1.7.7 (#123)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Upgrade zio-json to 0.3.0-RC1-1

* Update zio-prelude and zio-optics versions to ZIO-2 releases and address Adam's PR feedback

* Last bit of PR cleanup

* Fix linter error

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>

* Update ZIO2 branch to latest main (#216)

* Update dependency ch.epfl.scala:sbt-scalafix to v0.9.33 (#98)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Capture annotations on Enums and all cases (#167)

* Capture annotations on Enums and all cases

* Linting

* Update dependency com.github.ghik:silencer-lib to v1.7.7 (#123)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-scalafmt to v2.4.5 (#154)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Add schema for DynamicValue (#170)

* Add Schema for DynamicValue

* Rename some of StandardType values

* Fix type casting

* Fix linting issues

Run `prepare` on the whole project

* Support native schema for Set #139 (#173)

* Support native schema for Set

* added Diff support for SetSchema

* removed dead code

* attempt to fix scala 2.13 match may not be exhaustive compile error

* added SetSchema support

* updated docs to mention zio-dynamoDB as a client

* More property based tests for map and set (#178)

* added more property based tests for Map

* added more property based tests for Set

* Diff refactor (#176)

* Diff refactor

Refactor diff. There are two main goals:

1. Add type parameter to `Dff`. This solves an otherwise very nasty issue in the Scala 3 support.

2. Use Least Common Subsequence (LCS aka Myers Diff) for all sequence diffs. This simplifies things a lot of unifies all collection diffs under a single, principled algorithm.

* Linter fixes

* Fix 2.12 build issue

* Move LCSDiff to Differ companion object

* Make LCSDiff package private

* Linting

Co-authored-by: John A. De Goes <john@degoes.net>

* Update dependency org.scala-native:sbt-scala-native to v0.4.3 (#180)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-mdoc to v2.3.0 (#181)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Thrift (#163)

* thrift

* all tests passing

* uncommented benchmarks

* sets

* removed not implemented methods

* map

* fixes

* formatting

* small fixes

* fixes

* fixes

* failure decoding

* path as first param

* Fix compile errors for Scala 2.12

* code review

* thrift optionals

* scalafmt + compilation warnings

* removed JavaConverters

* removed JavaConverters

* scalafmt

* scalafix

* scalafix test

Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>

* Fix bug in enum schema derivation (#191)

* Unify schema of Either/Left/Right (#204)

* Update dependency org.xerial.sbt:sbt-sonatype to v3.9.12 (#186)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scala-js:sbt-scalajs to v1.9.0 (#190)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency com.eed3si9n:sbt-buildinfo to v0.11.0 (#199)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Equality implementation for Schema (#206)

* Equality implementation for Schema

* Import order fix

* Improve equality of Sequence

* Fix equality, recursion, migration

* Fix warning

* Run fix

* Manually fix scalafix result

* preserve annotations when calling toRecord on a Tuple: fixes #212 (#213)

* preserve annotations when calling toRecord on a Tuple: fixes #212

* apply scalafixAll

* Format

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>
Co-authored-by: Ivan Grebenik <1790371+igrebenik@users.noreply.github.com>
Co-authored-by: Avinder Bahra <abahra@equalexperts.com>
Co-authored-by: Avinder Bahra <avinder.bahra@gmail.com>
Co-authored-by: John A. De Goes <john@degoes.net>
Co-authored-by: František Kocun <frantisek.kocun@gmail.com>
Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Tobias Pfeifer <TobiasPfeifer@users.noreply.github.com>

* ZIO2 latest update from main (#222)

* Update dependency ch.epfl.scala:sbt-scalafix to v0.9.33 (#98)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Capture annotations on Enums and all cases (#167)

* Capture annotations on Enums and all cases

* Linting

* Update dependency com.github.ghik:silencer-lib to v1.7.7 (#123)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-scalafmt to v2.4.5 (#154)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Add schema for DynamicValue (#170)

* Add Schema for DynamicValue

* Rename some of StandardType values

* Fix type casting

* Fix linting issues

Run `prepare` on the whole project

* Support native schema for Set #139 (#173)

* Support native schema for Set

* added Diff support for SetSchema

* removed dead code

* attempt to fix scala 2.13 match may not be exhaustive compile error

* added SetSchema support

* updated docs to mention zio-dynamoDB as a client

* More property based tests for map and set (#178)

* added more property based tests for Map

* added more property based tests for Set

* Diff refactor (#176)

* Diff refactor

Refactor diff. There are two main goals:

1. Add type parameter to `Dff`. This solves an otherwise very nasty issue in the Scala 3 support.

2. Use Least Common Subsequence (LCS aka Myers Diff) for all sequence diffs. This simplifies things a lot of unifies all collection diffs under a single, principled algorithm.

* Linter fixes

* Fix 2.12 build issue

* Move LCSDiff to Differ companion object

* Make LCSDiff package private

* Linting

Co-authored-by: John A. De Goes <john@degoes.net>

* Update dependency org.scala-native:sbt-scala-native to v0.4.3 (#180)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-mdoc to v2.3.0 (#181)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Thrift (#163)

* thrift

* all tests passing

* uncommented benchmarks

* sets

* removed not implemented methods

* map

* fixes

* formatting

* small fixes

* fixes

* fixes

* failure decoding

* path as first param

* Fix compile errors for Scala 2.12

* code review

* thrift optionals

* scalafmt + compilation warnings

* removed JavaConverters

* removed JavaConverters

* scalafmt

* scalafix

* scalafix test

Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>

* Fix bug in enum schema derivation (#191)

* Unify schema of Either/Left/Right (#204)

* Update dependency org.xerial.sbt:sbt-sonatype to v3.9.12 (#186)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scala-js:sbt-scalajs to v1.9.0 (#190)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency com.eed3si9n:sbt-buildinfo to v0.11.0 (#199)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Equality implementation for Schema (#206)

* Equality implementation for Schema

* Import order fix

* Improve equality of Sequence

* Fix equality, recursion, migration

* Fix warning

* Run fix

* Manually fix scalafix result

* preserve annotations when calling toRecord on a Tuple: fixes #212 (#213)

* preserve annotations when calling toRecord on a Tuple: fixes #212

* apply scalafixAll

* Add special encoding for List and Map types in SchemaAst (#220)

* Add special encoding for List and Map types in SchemaAst

* revert build config chnage

* preserve optional flag

* Fix

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>
Co-authored-by: Ivan Grebenik <1790371+igrebenik@users.noreply.github.com>
Co-authored-by: Avinder Bahra <abahra@equalexperts.com>
Co-authored-by: Avinder Bahra <avinder.bahra@gmail.com>
Co-authored-by: John A. De Goes <john@degoes.net>
Co-authored-by: František Kocun <frantisek.kocun@gmail.com>
Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Tobias Pfeifer <TobiasPfeifer@users.noreply.github.com>

* Dynamic and SemiDynamic schemas ZIO 2 version (#219)

* Update dependency ch.epfl.scala:sbt-scalafix to v0.9.33 (#98)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Capture annotations on Enums and all cases (#167)

* Capture annotations on Enums and all cases

* Linting

* Update dependency com.github.ghik:silencer-lib to v1.7.7 (#123)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-scalafmt to v2.4.5 (#154)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Add schema for DynamicValue (#170)

* Add Schema for DynamicValue

* Rename some of StandardType values

* Fix type casting

* Fix linting issues

Run `prepare` on the whole project

* Support native schema for Set #139 (#173)

* Support native schema for Set

* added Diff support for SetSchema

* removed dead code

* attempt to fix scala 2.13 match may not be exhaustive compile error

* added SetSchema support

* updated docs to mention zio-dynamoDB as a client

* More property based tests for map and set (#178)

* added more property based tests for Map

* added more property based tests for Set

* Diff refactor (#176)

* Diff refactor

Refactor diff. There are two main goals:

1. Add type parameter to `Dff`. This solves an otherwise very nasty issue in the Scala 3 support.

2. Use Least Common Subsequence (LCS aka Myers Diff) for all sequence diffs. This simplifies things a lot of unifies all collection diffs under a single, principled algorithm.

* Linter fixes

* Fix 2.12 build issue

* Move LCSDiff to Differ companion object

* Make LCSDiff package private

* Linting

Co-authored-by: John A. De Goes <john@degoes.net>

* Update dependency org.scala-native:sbt-scala-native to v0.4.3 (#180)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scalameta:sbt-mdoc to v2.3.0 (#181)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Thrift (#163)

* thrift

* all tests passing

* uncommented benchmarks

* sets

* removed not implemented methods

* map

* fixes

* formatting

* small fixes

* fixes

* fixes

* failure decoding

* path as first param

* Fix compile errors for Scala 2.12

* code review

* thrift optionals

* scalafmt + compilation warnings

* removed JavaConverters

* removed JavaConverters

* scalafmt

* scalafix

* scalafix test

Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>

* Fix bug in enum schema derivation (#191)

* Dynamic and SemiDynamic schemas

* Unify schema of Either/Left/Right (#204)

* DeriveGen

* JsonCodec

* Fix semiDynamicEncoder

* Fixes

* Update dependency org.xerial.sbt:sbt-sonatype to v3.9.12 (#186)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency org.scala-js:sbt-scalajs to v1.9.0 (#190)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update dependency com.eed3si9n:sbt-buildinfo to v0.11.0 (#199)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Equality implementation for Schema (#206)

* Equality implementation for Schema

* Import order fix

* Improve equality of Sequence

* Fix equality, recursion, migration

* Fix warning

* Run fix

* Manually fix scalafix result

* Json codec works

* BigInt, BigDecimal support for protobuf

* Fix protobuf semi dynamic record test

* Various thrift codec fixes

* SemiDynamic support for thrift

* Fix some warnings

* Fix more warnings

* Fix compilation on 2.12

* scalafix

* format

* preserve annotations when calling toRecord on a Tuple: fixes #212 (#213)

* preserve annotations when calling toRecord on a Tuple: fixes #212

* apply scalafixAll

* Reproducer for schema ast materialization problem

* Format

* Finish todo items

* Fix bug in AST (#223)

* Fix bug in AST

* Remove unused import

* Unused import

* deprecate testM abd checM

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>
Co-authored-by: Ivan Grebenik <1790371+igrebenik@users.noreply.github.com>
Co-authored-by: Avinder Bahra <abahra@equalexperts.com>
Co-authored-by: Avinder Bahra <avinder.bahra@gmail.com>
Co-authored-by: John A. De Goes <john@degoes.net>
Co-authored-by: František Kocun <frantisek.kocun@gmail.com>
Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Tobias Pfeifer <TobiasPfeifer@users.noreply.github.com>

* Remove DynamicValue.Transform (#227)

* Support for ZIO2-RC3 (#230)

* Upgrade to ZIO2 RC2

* Update to ZIO2 RC3

* Upgrade zio-json snapshot version for ZIO2-RC3

* Fix string encoding compilation error

* Try to get timeouts sorted

* Upgrade To ZIO 2.0.0-RC4 (#234)

* upgrade zio version

* remove unused import

* ZIO 2.0.0-RC5 (#238)

* Upgrade to ZIO 2.0.0-RC6 (#245)

* Upgrade to ZIO 2.0.0-RC6

* Convert error to string

* Fix schema derivation test

* Migrate test

* Switch to ZPipeline.utf8Decode

* Fix JSON decode

* fix and format

Co-authored-by: Daniel Vigovszky <daniel.vigovszky@gmail.com>

* Fix protobuf semidynamic encoding/decoding (#266)

* Remove Left/Right/None/Nil implicit schemas (#279)

* Fix for DynamicValue.Record field order mixed up by serialization  (#284)

* Reproducer for Dynamic Record field order issue

* Fix

* Update to ZIO 2.0.0 final (#290)

* feature: add `toTypedPrimitive` operator to `StandardType` (#300)

* feature: add `toTypedPrimitive` operator to StandardType

* chore: update style

* Fix

* Fixes

* Settings fix

* Fix build helper

* Scala 3 fixes

* Thrift codec Scala3 fixes

* Scala3 fix

* More Scala3 fix

* Copied memory settings from zio/zio

* Trying other memory settings

* More fixes

* Force rebuild

* Make AvroCodec Scala 2.12 compatible

* ScalaFix

* ZIO 2.0.1

* Disable parallel execution on CI

* Do not fork tests

Co-authored-by: Alexander van Olst <alexvanolst@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Dan Harris <1327726+thinkharderdev@users.noreply.github.com>
Co-authored-by: Ivan Grebenik <1790371+igrebenik@users.noreply.github.com>
Co-authored-by: Avinder Bahra <abahra@equalexperts.com>
Co-authored-by: Avinder Bahra <avinder.bahra@gmail.com>
Co-authored-by: John A. De Goes <john@degoes.net>
Co-authored-by: František Kocun <frantisek.kocun@gmail.com>
Co-authored-by: Dan Harris <dan@thinkharder.dev>
Co-authored-by: Tobias Pfeifer <TobiasPfeifer@users.noreply.github.com>
Co-authored-by: Adam Fraser <adam.fraser@gmail.com>
Co-authored-by: Denis <denisgarci@users.noreply.github.com>
Co-authored-by: Albert Pető <petoalbert32@gmail.com>
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants