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

Improve laziness of typeclass derivation #658

Merged
merged 7 commits into from
Dec 6, 2020
Merged

Improve laziness of typeclass derivation #658

merged 7 commits into from
Dec 6, 2020

Conversation

ghostdogpr
Copy link
Owner

Continuation of #594 and @darl's work to make sure Magnolia uses the custom typeclass instances before it tries to derive it.

@ghostdogpr
Copy link
Owner Author

ghostdogpr commented Nov 26, 2020

There is one drawback to having one level of indirection when calling Magnolia, which is that you don't get Magnolia detailed error messages when calling gen[A] explicitly. Instead, you get an error saying it can't find the implicit Derived.

You can get the detailed error by calling autogen[A].schema but that's less straightforward.

@ghostdogpr
Copy link
Owner Author

Maybe it's fine if I document it. gen[A] will still work so no breaking change, and autogen[A].schema can be recommended for debugging.

@paulpdaniels any opinion on this?

@paulpdaniels
Copy link
Collaborator

I'm fine with this, it's all still magic to me. I wonder though could we have some way of surfacing the autogen distinction in the error message? Or perhaps we could add it to the scaladocs on gen?

@ghostdogpr
Copy link
Owner Author

I don't think we can surface the error message because gen is not calling the macro itself, it is only checking if there is an implicit in scope.

Good point on the documentation. I think I will rename autogen to genMacro too, the difference will be clearer.

@ghostdogpr ghostdogpr merged commit 7d69874 into master Dec 6, 2020
@ghostdogpr ghostdogpr deleted the derivation branch December 6, 2020 06:07
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.

None yet

2 participants