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

Support for value classes #435

Merged
merged 19 commits into from
Dec 13, 2022
Merged

Support for value classes #435

merged 19 commits into from
Dec 13, 2022

Conversation

micsza
Copy link
Contributor

@micsza micsza commented Nov 22, 2022

Implements support for mirrorless value classes derivation for non-generic products with annotations and default values.

TODOs:

  1. support for non-product value classes
  2. support for generic value classes
  3. support for access modifiers

src/core/interface.scala Outdated Show resolved Hide resolved
src/core/magnolia.scala Outdated Show resolved Hide resolved
src/core/magnolia.scala Outdated Show resolved Hide resolved
src/core/impl.scala Outdated Show resolved Hide resolved
build.sbt Outdated Show resolved Hide resolved
val res = SemiDefault.derived[WithDefault].default
assertEquals(res, WithDefault(123))
}

// test("serialize a value class") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are we missing to enable these tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok I see above :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment fo reach test why it fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - but what's a product value class? Do you mean case classes? If so, ServiceName1 is a case class, but it is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean case classes - ServiceName test is now enabled.

src/test/SumsTests.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
src/core/macro.scala Outdated Show resolved Hide resolved
Copy link
Member

@adamw adamw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some code duplication which I think we can remove

@micsza micsza changed the title [wip] Support for value classes Support for value classes Dec 13, 2022
)
assert(
error contains "trait Parent is not a generic sum because its child trait BadChild is not a generic product because it is not a case class"
error contains "Deriving the typeclass based on mirrors or directly is not possible for \"magnolia1.tests.SumsTests.Parent\":String. Please refer to the documentation or report a feature request."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this :String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved.


case t: TypeTree => t.tpe

// case for AnyVal type annotations: with "-Yretain-trees" scalac option, the TypeTree of the annotation gets erased,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the option, or without the option? It would seem on first sight that trees get erased without retain-trees :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tricky as it seems, it is with that option. It appears that -Yretain-trees may change the types of the trees, f.e. scala/scala3#14195.

Copy link
Member

@adamw adamw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! :)

@adamw adamw merged commit 0bb10e0 into scala3 Dec 13, 2022
@adamw adamw deleted the value_classes branch December 13, 2022 14:02
@adamw adamw mentioned this pull request Dec 13, 2022
5 tasks
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