Skip to content

Commit 5f19c1d

Browse files
committed
Remove erasure logic from ContextFunctionType
[Cherry-picked 350dfa7][modified]
1 parent 0fda02c commit 5f19c1d

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,17 +1882,14 @@ class Definitions {
18821882
*/
18831883
object ContextFunctionType:
18841884
def unapply(tp: Type)(using Context): Option[(List[Type], Type, List[Boolean])] =
1885-
if ctx.erasedTypes then
1886-
atPhase(erasurePhase)(unapply(tp))
1887-
else
1888-
asContextFunctionType(tp) match
1889-
case ErasedFunctionOf(mt) =>
1890-
Some((mt.paramInfos, mt.resType, mt.erasedParams))
1891-
case tp1 if tp1.exists =>
1892-
val args = tp1.functionArgInfos
1893-
val erasedParams = erasedFunctionParameters(tp1)
1894-
Some((args.init, args.last, erasedParams))
1895-
case _ => None
1885+
asContextFunctionType(tp) match
1886+
case PolyFunctionOf(mt: MethodType) =>
1887+
Some((mt.paramInfos, mt.resType, mt.erasedParams))
1888+
case tp1 if tp1.exists =>
1889+
val args = tp1.functionArgInfos
1890+
val erasedParams = List.fill(functionArity(tp1)) { false }
1891+
Some((args.init, args.last, erasedParams))
1892+
case _ => None
18961893

18971894
/* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
18981895
def erasedFunctionParameters(tp: Type)(using Context): List[Boolean] = tp.dealias match {

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,24 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
129129
assert(ctx.typer.isInstanceOf[Erasure.Typer])
130130
ctx.typer.typed(untpd.cpy.Apply(ref)(ref, args), member.info.finalResultType)
131131
else
132-
val defn.ContextFunctionType(argTypes, resType, erasedParams) = tp: @unchecked
133-
val anonFun = newAnonFun(ctx.owner,
134-
MethodType(
135-
argTypes.zip(erasedParams.padTo(argTypes.length, false))
136-
.flatMap((t, e) => if e then None else Some(t)),
137-
resType),
138-
coord = ctx.owner.coord)
132+
val mtWithoutErasedParams = atPhase(erasurePhase) {
133+
val defn.ContextFunctionType(argTypes, resType, erasedParams) = tp.dealias: @unchecked
134+
val paramInfos = argTypes.zip(erasedParams).collect { case (argType, erased) if !erased => argType }
135+
MethodType(paramInfos, resType)
136+
}
137+
val anonFun = newAnonFun(ctx.owner, mtWithoutErasedParams, coord = ctx.owner.coord)
139138
anonFun.info = transformInfo(anonFun, anonFun.info)
140139

141140
def lambdaBody(refss: List[List[Tree]]) =
142141
val refs :: Nil = refss: @unchecked
143142
val expandedRefs = refs.map(_.withSpan(ctx.owner.span.endPos)) match
144143
case (bunchedParam @ Ident(nme.ALLARGS)) :: Nil =>
145-
argTypes.indices.toList.map(n =>
144+
mtWithoutErasedParams.paramInfos.indices.toList.map(n =>
146145
bunchedParam
147146
.select(nme.primitive.arrayApply)
148147
.appliedTo(Literal(Constant(n))))
149148
case refs1 => refs1
150-
expand(args ::: expandedRefs, resType, n - 1)(using ctx.withOwner(anonFun))
149+
expand(args ::: expandedRefs, mtWithoutErasedParams.resType, n - 1)(using ctx.withOwner(anonFun))
151150

152151
val unadapted = Closure(anonFun, lambdaBody)
153152
cpy.Block(unadapted)(unadapted.stats,

0 commit comments

Comments
 (0)