Open MateuszKubuszok opened 1 month ago
@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 NewType
, please provide implicit JsonValueCodec[NewType]
" or something similar would be good.
So something better than exception, even "cannot automatically handle the type
NewType
, please provide implicitJsonValueCodec[NewType]
" or something similar would be good.
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:
primaryConstructor
For Scala 2, there is isPublic
method, for Scala 3 (in my macros) I was checking for absence of Flags.Private
, Flags.Protected
and emptiness of sym.privateWithin
and sym.protectedWithin
.
The hard way would use Scala 2's:
sym.isPublic: Boolean
sym.isProtected: Boolean
sym.isPrivate: Boolean
sym.isPrivateWithin: Symbol
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.