@@ -1255,6 +1255,24 @@ class Typer extends Namer
12551255            if  (bounds !=  null ) sym.info =  bounds
12561256          }
12571257          b
1258+         case  t : UnApply  if  t.symbol.is(Inline ) => 
1259+           //  An inline unapply `P.unapply` in a plattern `P(x1,x2,...)` is transformed into
1260+           //  `{ class $anon { def unapply(x1: T1, x2: T2, ...): R = P.unapply(x1, x2, ...) }; new $anon }.unapply`
1261+           //  and the call `P.unapply(x1, x2, ...)` is inlined.
1262+           val  sym  =  t.symbol
1263+           val  cls  =  ctx.newNormalizedClassSymbol(ctx.owner, tpnme.ANON_CLASS , Synthetic  |  Final , List (defn.ObjectType ), coord =  sym.coord)
1264+           val  constr  =  ctx.newConstructor(cls, Synthetic , Nil , Nil , coord =  sym.coord).entered
1265+           val  unappplySym  =  ctx.newSymbol(cls, sym.name.toTermName, Synthetic  |  Method , sym.info, coord =  sym.coord).entered
1266+           val  unapply  =  polyDefDef(unappplySym, targs =>  argss => 
1267+             Inliner .inlineCall(ref(sym).appliedToTypes(targs).appliedToArgss(argss).withSpan(t.span))
1268+           )
1269+           val  cdef  =  ClassDef (cls, DefDef (constr), List (unapply))
1270+           val  newUnapply  =  Block (cdef ::  Nil , New (cls.typeRef, Nil ))
1271+           val  targs  =  t.fun match 
1272+             case  TypeApply (_, targs) =>  targs
1273+             case  _ =>  Nil 
1274+           val  newFun  =  newUnapply.select(unappplySym).appliedToTypeTrees(targs).withSpan(t.span)
1275+           cpy.UnApply (t)(newFun, t.implicits, t.patterns)
12581276        case  t =>  t
12591277      }
12601278  }
0 commit comments