Skip to content

Commit 4c77f62

Browse files
Improve erased params logic (#18433)
Part of #18305
2 parents 3df2ed3 + fa1f79d commit 4c77f62

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ object TypeErasure {
567567
functionType(info.resultType)
568568
case info: MethodType =>
569569
assert(!info.resultType.isInstanceOf[MethodicType])
570-
defn.FunctionType(n = info.erasedParams.count(_ == false))
570+
defn.FunctionType(n = info.nonErasedParamCount)
571571
}
572572
erasure(functionType(applyInfo))
573573
}

compiler/src/dotty/tools/dotc/core/Types.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -3724,8 +3724,6 @@ object Types {
37243724

37253725
def companion: LambdaTypeCompanion[ThisName, PInfo, This]
37263726

3727-
def erasedParams(using Context) = List.fill(paramInfos.size)(false)
3728-
37293727
/** The type `[tparams := paramRefs] tp`, where `tparams` can be
37303728
* either a list of type parameter symbols or a list of lambda parameters
37313729
*
@@ -4017,13 +4015,18 @@ object Types {
40174015
final override def isImplicitMethod: Boolean =
40184016
companion.eq(ImplicitMethodType) || isContextualMethod
40194017
final override def hasErasedParams(using Context): Boolean =
4020-
erasedParams.contains(true)
4018+
paramInfos.exists(p => p.hasAnnotation(defn.ErasedParamAnnot))
4019+
40214020
final override def isContextualMethod: Boolean =
40224021
companion.eq(ContextualMethodType)
40234022

4024-
override def erasedParams(using Context): List[Boolean] =
4023+
def erasedParams(using Context): List[Boolean] =
40254024
paramInfos.map(p => p.hasAnnotation(defn.ErasedParamAnnot))
40264025

4026+
def nonErasedParamCount(using Context): Int =
4027+
paramInfos.count(p => !p.hasAnnotation(defn.ErasedParamAnnot))
4028+
4029+
40274030
protected def prefixString: String = companion.prefixString
40284031
}
40294032

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
297297
"(" ~ toTextRef(tp) ~ " : " ~ toTextGlobal(tp.underlying) ~ ")"
298298

299299
protected def paramsText(lam: LambdaType): Text = {
300-
val erasedParams = lam.erasedParams
301-
def paramText(ref: ParamRef, erased: Boolean) =
300+
def paramText(ref: ParamRef) =
301+
val erased = ref.underlying.hasAnnotation(defn.ErasedParamAnnot)
302302
keywordText("erased ").provided(erased) ~ ParamRefNameString(ref) ~ lambdaHash(lam) ~ toTextRHS(ref.underlying, isParameter = true)
303-
Text(lam.paramRefs.lazyZip(erasedParams).map(paramText), ", ")
303+
Text(lam.paramRefs.map(paramText), ", ")
304304
}
305305

306306
protected def ParamRefNameString(name: Name): String = nameString(name)

compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ object ContextFunctionResults:
8585
else
8686
val defn.ContextFunctionType(params, resTpe, erasedParams) = tp: @unchecked
8787
val rest = contextParamCount(resTpe, crCount - 1)
88-
if erasedParams.contains(true) then erasedParams.count(_ == false) + rest else params.length + rest
88+
// TODO use mt.nonErasedParamCount
89+
if erasedParams.contains(true) then erasedParams.count(_ == false) + rest else params.length + rest // TODO use mt.nonErasedParamCount
8990

9091
def normalParamCount(tp: Type): Int = tp.widenExpr.stripPoly match
91-
case mt @ MethodType(pnames) =>
92-
val rest = normalParamCount(mt.resType)
93-
if mt.hasErasedParams then
94-
mt.erasedParams.count(_ == false) + rest
95-
else pnames.length + rest
92+
case mt @ MethodType(pnames) => mt.nonErasedParamCount + normalParamCount(mt.resType)
9693
case _ => contextParamCount(tp, contextResultCount(sym))
9794

9895
normalParamCount(sym.info)

0 commit comments

Comments
 (0)