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

Read scala default values, if no fieldDefaultValue annotation is found #562

Merged
merged 6 commits into from
Sep 6, 2023

Conversation

987Nabil
Copy link
Contributor

fixes #552
/claim #552

@liewhite
Copy link
Contributor

liewhite commented Jun 1, 2023

Any progress?

jdegoes
jdegoes previously approved these changes Jun 2, 2023
@987Nabil
Copy link
Contributor Author

987Nabil commented Jun 3, 2023

@jdegoes I fixed the linting errors

@liewhite
Copy link
Contributor

I test this locally, it failed on generic field.

@987Nabil
Copy link
Contributor Author

@liewhite Can you provide a reproducer and tell me for which Scala version?

.declaredMethod(s"$$apply$$default$$$i")
.headOption
)
.map(Select(Ref(from.companionModule), _).asExpr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Compiling failed on Generic case class here.

@liewhite
Copy link
Contributor

@liewhite Can you provide a reproducer and tell me for which Scala version?

case class A[T](a: Option[T], b: Int) derives Schema

Compilation failed with not a Expr error.

I comment in code view

@987Nabil
Copy link
Contributor Author

Thanks. I'll take a look soon.

@liewhite
Copy link
Contributor

liewhite commented Jun 15, 2023

Thanks. I'll take a look soon.

if(i.isExpr) {
        i.asExpr
}else {
        i.appliedToType(TypeRepr.of[Any]).asExpr
}

This works.
But is it safe to use any after compiler type check?

@987Nabil
Copy link
Contributor Author

987Nabil commented Jun 30, 2023

@liewhite Finally found some time. Your solution is ok, since when we call toExpr it ends up being an Expr[Any] anyway.
But there have been more problems I needed to fix. Now it looks ok.

@jdegoes I could not use a generic implicit for the test of the generic class. If I do it, the gen macro for Scala 3 fails. But this seems to be a problem that existed before my changes. I'll open a bg ticket. Edit: #580

vigoo
vigoo previously approved these changes Sep 5, 2023
@vigoo vigoo merged commit 1a9ab2b into zio:main Sep 6, 2023
13 checks passed
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.

Get default value from case class default paramters
4 participants