@@ -28,26 +28,35 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
2828 private type SpecialHandlers = List [(ClassSymbol , SpecialHandler )]
2929
3030 val synthesizedClassTag : SpecialHandler = (formal, span) =>
31- formal.argInfos match
32- case arg :: Nil =>
33- if isFullyDefined(arg, ForceDegree .all) then
34- arg match
35- case defn.ArrayOf (elemTp) =>
36- val etag = typer.inferImplicitArg(defn.ClassTagClass .typeRef.appliedTo(elemTp), span)
37- if etag.tpe.isError then EmptyTreeNoError else withNoErrors(etag.select(nme.wrap))
38- case tp if hasStableErasure(tp) && ! defn.isBottomClassAfterErasure(tp.typeSymbol) =>
39- val sym = tp.typeSymbol
40- val classTag = ref(defn.ClassTagModule )
41- val tag =
42- if defn.SpecialClassTagClasses .contains(sym) then
43- classTag.select(sym.name.toTermName)
44- else
45- val clsOfType = escapeJavaArray(erasure(tp))
46- classTag.select(nme.apply).appliedToType(tp).appliedTo(clsOf(clsOfType))
47- withNoErrors(tag.withSpan(span))
48- case tp => EmptyTreeNoError
49- else EmptyTreeNoError
50- case _ => EmptyTreeNoError
31+ val tag = formal.argInfos match
32+ case arg :: Nil if isFullyDefined(arg, ForceDegree .all) =>
33+ arg match
34+ case defn.ArrayOf (elemTp) =>
35+ val etag = typer.inferImplicitArg(defn.ClassTagClass .typeRef.appliedTo(elemTp), span)
36+ if etag.tpe.isError then EmptyTree else etag.select(nme.wrap)
37+ case tp if hasStableErasure(tp) && ! defn.isBottomClassAfterErasure(tp.typeSymbol) =>
38+ val sym = tp.typeSymbol
39+ val classTagModul = ref(defn.ClassTagModule )
40+ if defn.SpecialClassTagClasses .contains(sym) then
41+ classTagModul.select(sym.name.toTermName).withSpan(span)
42+ else
43+ def clsOfType (tp : Type ): Type = tp.dealias.underlyingMatchType match
44+ case matchTp : MatchType =>
45+ matchTp.alternatives.map(clsOfType) match
46+ case ct1 :: cts if cts.forall(ct1 == _) => ct1
47+ case _ => NoType
48+ case _ =>
49+ escapeJavaArray(erasure(tp))
50+ val ctype = clsOfType(tp)
51+ if ctype.exists then
52+ classTagModul.select(nme.apply)
53+ .appliedToType(tp)
54+ .appliedTo(clsOf(ctype))
55+ .withSpan(span)
56+ else EmptyTree
57+ case _ => EmptyTree
58+ case _ => EmptyTree
59+ (tag, Nil )
5160 end synthesizedClassTag
5261
5362 val synthesizedTypeTest : SpecialHandler =
0 commit comments