diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 94c7b2993b97..c201ecd06054 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -567,7 +567,7 @@ object TypeErasure { functionType(info.resultType) case info: MethodType => assert(!info.resultType.isInstanceOf[MethodicType]) - defn.FunctionType(n = info.erasedParams.count(_ == false)) + defn.FunctionType(n = info.nonErasedParamCount) } erasure(functionType(applyInfo)) } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index fcf9d984bcf4..ba7d4e7576c1 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3721,8 +3721,6 @@ object Types { def companion: LambdaTypeCompanion[ThisName, PInfo, This] - def erasedParams(using Context) = List.fill(paramInfos.size)(false) - /** The type `[tparams := paramRefs] tp`, where `tparams` can be * either a list of type parameter symbols or a list of lambda parameters * @@ -4014,13 +4012,18 @@ object Types { final override def isImplicitMethod: Boolean = companion.eq(ImplicitMethodType) || isContextualMethod final override def hasErasedParams(using Context): Boolean = - erasedParams.contains(true) + paramInfos.exists(p => p.hasAnnotation(defn.ErasedParamAnnot)) + final override def isContextualMethod: Boolean = companion.eq(ContextualMethodType) - override def erasedParams(using Context): List[Boolean] = + def erasedParams(using Context): List[Boolean] = paramInfos.map(p => p.hasAnnotation(defn.ErasedParamAnnot)) + def nonErasedParamCount(using Context): Int = + paramInfos.count(p => !p.hasAnnotation(defn.ErasedParamAnnot)) + + protected def prefixString: String = companion.prefixString } diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 4d87d6406567..b739bcf1b74d 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -297,10 +297,10 @@ class PlainPrinter(_ctx: Context) extends Printer { "(" ~ toTextRef(tp) ~ " : " ~ toTextGlobal(tp.underlying) ~ ")" protected def paramsText(lam: LambdaType): Text = { - val erasedParams = lam.erasedParams - def paramText(ref: ParamRef, erased: Boolean) = + def paramText(ref: ParamRef) = + val erased = ref.underlying.hasAnnotation(defn.ErasedParamAnnot) keywordText("erased ").provided(erased) ~ ParamRefNameString(ref) ~ lambdaHash(lam) ~ toTextRHS(ref.underlying, isParameter = true) - Text(lam.paramRefs.lazyZip(erasedParams).map(paramText), ", ") + Text(lam.paramRefs.map(paramText), ", ") } protected def ParamRefNameString(name: Name): String = nameString(name) diff --git a/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala b/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala index b4eb71c541d3..b9478fb893a0 100644 --- a/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala +++ b/compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala @@ -85,14 +85,11 @@ object ContextFunctionResults: else val defn.ContextFunctionType(params, resTpe, erasedParams) = tp: @unchecked val rest = contextParamCount(resTpe, crCount - 1) - if erasedParams.contains(true) then erasedParams.count(_ == false) + rest else params.length + rest + // TODO use mt.nonErasedParamCount + if erasedParams.contains(true) then erasedParams.count(_ == false) + rest else params.length + rest // TODO use mt.nonErasedParamCount def normalParamCount(tp: Type): Int = tp.widenExpr.stripPoly match - case mt @ MethodType(pnames) => - val rest = normalParamCount(mt.resType) - if mt.hasErasedParams then - mt.erasedParams.count(_ == false) + rest - else pnames.length + rest + case mt @ MethodType(pnames) => mt.nonErasedParamCount + normalParamCount(mt.resType) case _ => contextParamCount(tp, contextResultCount(sym)) normalParamCount(sym.info)