@@ -1299,7 +1299,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1299
1299
1300
1300
val numArgs = args.length
1301
1301
val isContextual = funFlags.is(Given )
1302
- val isErased = funFlags. is(Erased )
1302
+ val isErased = args.collect({ case x : untpd. ValDef => x }).exists(_.mods.flags. is(Erased ) )
1303
1303
val isImpure = funFlags.is(Impure )
1304
1304
val funSym = defn.FunctionSymbol (numArgs, isContextual, isErased, isImpure)
1305
1305
@@ -1353,7 +1353,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1353
1353
}
1354
1354
}
1355
1355
1356
- def typedFunctionValue (tree : untpd.Function , pt : Type )(using Context ): Tree = {
1356
+ def typedFunctionValue (tree : untpd.Function , pt : Type )(using Context ): Tree = trace.force( s " typedFunctionValue ${tree.show} => ${pt.show} " , show = true ) {
1357
1357
val untpd .Function (params : List [untpd.ValDef ] @ unchecked, _) = tree : @ unchecked
1358
1358
1359
1359
val isContextual = tree match {
@@ -1459,9 +1459,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1459
1459
1460
1460
val (protoFormals, resultTpt) = decomposeProtoFunction(pt, params.length, tree.srcPos)
1461
1461
1462
- def protoFormal (i : Int ): Type =
1463
- if (protoFormals.length == params.length) protoFormals(i)
1464
- else errorType(WrongNumberOfParameters (protoFormals.length), tree.srcPos)
1462
+ val protoIsErased = pt match {
1463
+ case RefinedType (_, _, mt : MethodType ) if mt.isErasedMethod =>
1464
+ mt.companion.asInstanceOf [ErasedMethodCompanion ].isErased
1465
+ case _ => List .fill(protoFormals.length)(false )
1466
+ }
1467
+
1468
+ /** Returns the type and whether the parameter is erased */
1469
+ def protoFormal (i : Int ): (Type , Boolean ) =
1470
+ if (protoFormals.length == params.length) (protoFormals(i), protoIsErased(i))
1471
+ else (errorType(WrongNumberOfParameters (protoFormals.length), tree.srcPos), false )
1465
1472
1466
1473
/** Is `formal` a product type which is elementwise compatible with `params`? */
1467
1474
def ptIsCorrectProduct (formal : Type ) =
@@ -1499,7 +1506,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1499
1506
for ((param, i) <- params.zipWithIndex) yield
1500
1507
if (! param.tpt.isEmpty) param
1501
1508
else
1502
- val formal = protoFormal(i)
1509
+ val ( formal, isErased) = protoFormal(i)
1503
1510
val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1504
1511
val paramType =
1505
1512
if knownFormal then formal
@@ -1510,14 +1517,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1510
1517
.withType(paramType.translateFromRepeated(toArray = false ))
1511
1518
.withSpan(param.span.endPos)
1512
1519
)
1513
- cpy.ValDef (param)(tpt = paramTpt)
1520
+ val param1 = if isErased then param.withAddedFlags(Flags .Erased ) else param
1521
+ println(s " > $param1 => $paramType => ${param1.mods.flags.is(Flags .Erased )}" )
1522
+ cpy.ValDef (param1)(tpt = paramTpt)
1514
1523
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span)
1524
+ println(s " >> ${desugared.show}" )
1515
1525
1516
1526
typed(desugared, pt)
1517
1527
.showing(i " desugared fun $tree --> $desugared with pt = $pt" , typr)
1518
1528
}
1519
1529
1520
- def typedClosure (tree : untpd.Closure , pt : Type )(using Context ): Tree = {
1530
+ def typedClosure (tree : untpd.Closure , pt : Type )(using Context ): Tree = trace.force( s " typedClosure ${tree.show} => ${pt.show} " , show = true ) {
1521
1531
val env1 = tree.env mapconserve (typed(_))
1522
1532
val meth1 = typedUnadapted(tree.meth)
1523
1533
val target =
0 commit comments