-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Better derivation error when the constructor is private #1198
Comments
@MateuszKubuszok Thanks for your feedback and using of jsoniter-scala in your presentation! What your expectations for better error messages in this case? |
In my presentation I want to show (among others) that a recursive derivation inside a macro:
when comparing with automatic and even semi-automatic derivation (based on Shapeless/Mirrors/Magnolia). So something better than exception, even "cannot automatically handle the type |
I don't know how detect that error at time of macro generation. I mean that usage can happen externally (and fail) or internally in the case object (and compile successfully), so just detection of the private flag in the primary constructor attribute will not help: class NewType private (val value: Int)
object NewType {
def unsafe(value: Int): NewType = new NewType(value)
implicit val codec: JsonValueCodec[NewType] = JsonCodecMaker.make
} |
The easy way would be to assume that OOTB macros would:
For Scala 2, there is The hard way would use Scala 2's:
as well as Scala 3's corresponding flags and methods and detect if constructor is visoble or not. |
I was testing the behavior of Circe and Jsoniter by deriving the codecs for
Out
case class defined like this:I wanted to compare error messages and how good they are.
I noticed that Jsoniter simply throws exception in the macro:
Scala 2
Scala 3
I believe that the error message could be improved.
The text was updated successfully, but these errors were encountered: