@@ -1769,24 +1769,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17691769 if (mt.isParamDependent)
17701770 report.error(em " $mt is an illegal function type because it has inter-parameter dependencies " , tree.srcPos)
17711771 // Restart typechecking if there are erased classes that we want to mark erased
1772- if mt.paramErasureStatuses.zip(mt.paramInfos.map(_.isErasedClass)).exists((paramErased, classErased) => classErased && ! paramErased) then
1773- val newParams = params3.zipWithConserve(mt.paramInfos.map(_.isErasedClass)) { (arg, isErasedClass) =>
1774- if isErasedClass then arg.withAddedFlags(Erased ) else arg
1775- }
1776- return typedDependent(newParams)
1777- val core =
1778- if mt.hasErasedParams then TypeTree (defn.PolyFunctionClass .typeRef)
1779- else
1780- val resTpt = TypeTree (mt.nonDependentResultApprox).withSpan(body.span)
1781- val paramTpts = appDef.termParamss.head.map(p => TypeTree (p.tpt.tpe).withSpan(p.tpt.span))
1782- val funSym = defn.FunctionSymbol (numArgs, isContextual)
1783- val tycon = TypeTree (funSym.typeRef)
1784- AppliedTypeTree (tycon, paramTpts :+ resTpt)
1785- val res = RefinedTypeTree (core, List (appDef), ctx.owner.asClass)
1786- if isImpure then
1787- typed(untpd.makeRetaining(untpd.TypedSplice (res), Nil , tpnme.retainsCap), pt)
1772+ if mt.paramErasureStatuses.lazyZip(mt.paramInfos).exists: (paramErased, info) =>
1773+ ! paramErased && info.derivesFrom(defn.ErasedClass )
1774+ then
1775+ val newParams = params3.zipWithConserve(mt.paramInfos): (param, info) =>
1776+ if info.derivesFrom(defn.ErasedClass ) then param.withAddedFlags(Erased ) else param
1777+ typedDependent(newParams)
17881778 else
1789- res
1779+ val core =
1780+ if mt.hasErasedParams then TypeTree (defn.PolyFunctionClass .typeRef)
1781+ else
1782+ val resTpt = TypeTree (mt.nonDependentResultApprox).withSpan(body.span)
1783+ val paramTpts = appDef.termParamss.head.map(p => TypeTree (p.tpt.tpe).withSpan(p.tpt.span))
1784+ val funSym = defn.FunctionSymbol (numArgs, isContextual)
1785+ val tycon = TypeTree (funSym.typeRef)
1786+ AppliedTypeTree (tycon, paramTpts :+ resTpt)
1787+ val res = RefinedTypeTree (core, List (appDef), ctx.owner.asClass)
1788+ if isImpure then
1789+ typed(untpd.makeRetaining(untpd.TypedSplice (res), Nil , tpnme.retainsCap), pt)
1790+ else
1791+ res
17901792 end typedDependent
17911793
17921794 args match {
@@ -1801,7 +1803,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18011803 val result = typed(cpy.AppliedTypeTree (tree)(untpd.TypeTree (funSym.typeRef), args :+ body), pt)
18021804 // if there are any erased classes, we need to re-do the typecheck.
18031805 result match
1804- case r : AppliedTypeTree if r.args.exists(_.tpe.isErasedClass ) =>
1806+ case r : AppliedTypeTree if r.args.init. exists(_.tpe.derivesFrom(defn. ErasedClass ) ) =>
18051807 typedFunctionType(desugar.makeFunctionWithValDefs(tree, pt), pt)
18061808 case _ => result
18071809 }
@@ -2944,6 +2946,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29442946 completeAnnotations(vdef, sym)
29452947 if sym.is(Implicit ) then checkImplicitConversionDefOK(sym)
29462948 if sym.is(Module ) then checkNoModuleClash(sym)
2949+ else if sym.info.derivesFrom(defn.ErasedClass ) then
2950+ sym.setFlag(Erased )
29472951 val tpt1 = checkSimpleKinded(typedType(tpt))
29482952 val rhs1 = vdef.rhs match
29492953 case rhs @ Ident (nme.WILDCARD ) =>
@@ -3068,16 +3072,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30683072 }
30693073
30703074 /** (1) Check that the signature of the class member does not return a repeated parameter type
3071- * (2) If info is an erased class, set erased flag of member
3072- * (3) Check that erased classes are not parameters of polymorphic functions.
3073- * (4) Make sure the definition's symbol is `sym`.
3074- * (5) Set the `defTree` of `sym` to be `mdef`.
3075+ * (2) Make sure the definition's symbol is `sym`.
3076+ * (3) Set the `defTree` of `sym` to be `mdef`.
30753077 */
30763078 private def postProcessInfo (mdef : MemberDef , sym : Symbol )(using Context ): MemberDef =
30773079 if (! sym.isOneOf(Synthetic | InlineProxy | Param ) && sym.info.finalResultType.isRepeatedParam)
30783080 report.error(em " Cannot return repeated parameter type ${sym.info.finalResultType}" , sym.srcPos)
3079- if ! sym.is(Module ) && ! sym.isConstructor && sym.info.finalResultType.isErasedClass then
3080- sym.setFlag(Erased )
30813081 mdef.ensureHasSym(sym)
30823082 mdef.setDefTree
30833083
0 commit comments