File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
core/src/main/scala/magnolia1 Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -111,10 +111,18 @@ object CaseClassDerivation:
111
111
val label = constValue[l].asInstanceOf [String ]
112
112
val tc = new SerializableFunction0 [Typeclass [p]]:
113
113
override def apply (): Typeclass [p] = summonInline[Typeclass [p]]
114
-
115
- val d = new SerializableFunction0 [Option [p]]:
116
- private def unsafeCast (any : Any ) = Option .when(any == null || (any : @ unchecked).isInstanceOf [p])(any.asInstanceOf [p])
117
- override def apply (): Option [p] = defaults.get(label).flatten.flatMap(d => unsafeCast(d.apply))
114
+ val evaluator : () => Any = defaults(label).orNull
115
+ val d =
116
+ if (evaluator ne null ) {
117
+ new SerializableFunction0 [Option [p]]:
118
+ override def apply (): Option [p] =
119
+ val v = evaluator()
120
+ if (v.isInstanceOf [p]) Some (v.asInstanceOf [p])
121
+ else None
122
+ } else {
123
+ new SerializableFunction0 [Option [p]]:
124
+ override def apply (): Option [p] = None
125
+ }
118
126
paramFromMaps[Typeclass , A , p](
119
127
label,
120
128
CallByNeed .createLazy(tc),
You can’t perform that action at this time.
0 commit comments