@@ -209,6 +209,8 @@ object Erasure {
209209 val tree1 =
210210 if (tree.tpe isRef defn.NullClass )
211211 adaptToType(tree, underlying)
212+ else if (wasPhantom(underlying))
213+ PhantomErasure .erasedParameterRef
212214 else if (! (tree.tpe <:< tycon)) {
213215 assert(! (tree.tpe.typeSymbol.isPrimitiveValueClass))
214216 val nullTree = Literal (Constant (null ))
@@ -418,6 +420,7 @@ object Erasure {
418420
419421 override def typedIdent (tree : untpd.Ident , pt : Type )(implicit ctx : Context ): tpd.Tree =
420422 if (tree.symbol eq defn.Phantom_assume ) PhantomErasure .erasedAssume
423+ else if (tree.symbol.is(Flags .Param ) && wasPhantom(tree.typeOpt)) PhantomErasure .erasedParameterRef
421424 else super .typedIdent(tree, pt)
422425
423426 override def typedThis (tree : untpd.This )(implicit ctx : Context ): Tree =
@@ -475,7 +478,8 @@ object Erasure {
475478 .withType(defn.ArrayOf (defn.ObjectType ))
476479 args0 = bunchedArgs :: Nil
477480 }
478- val args1 = args0.zipWithConserve(mt.paramInfos)(typedExpr)
481+ // Arguments are phantom if an only if the parameters are phantom, guaranteed by the separation of type lattices
482+ val args1 = args0.filterConserve(arg => ! wasPhantom(arg.typeOpt)).zipWithConserve(mt.paramInfos)(typedExpr)
479483 untpd.cpy.Apply (tree)(fun1, args1) withType mt.resultType
480484 case _ =>
481485 throw new MatchError (i " tree $tree has unexpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}" )
@@ -536,6 +540,11 @@ object Erasure {
536540 vparamss1 = (tpd.ValDef (bunchedParam) :: Nil ) :: Nil
537541 rhs1 = untpd.Block (paramDefs, rhs1)
538542 }
543+ vparamss1 = vparamss1.mapConserve(_.filterConserve(vparam => ! wasPhantom(vparam.tpe)))
544+ if (sym.is(Flags .ParamAccessor ) && wasPhantom(ddef.tpt.tpe)) {
545+ sym.resetFlag(Flags .ParamAccessor )
546+ rhs1 = PhantomErasure .erasedParameterRef
547+ }
539548 val ddef1 = untpd.cpy.DefDef (ddef)(
540549 tparams = Nil ,
541550 vparamss = vparamss1,
@@ -619,4 +628,7 @@ object Erasure {
619628
620629 def takesBridges (sym : Symbol )(implicit ctx : Context ) =
621630 sym.isClass && ! sym.is(Flags .Trait | Flags .Package )
631+
632+ private def wasPhantom (tp : Type )(implicit ctx : Context ): Boolean =
633+ tp.widenDealias.classSymbol eq defn.ErasedPhantomClass
622634}
0 commit comments