@@ -1473,17 +1473,21 @@ class Typer extends Namer
1473
1473
instantiateCFT(appType.instantiate(paramss.head.map(_.termRef)), paramss.tail)
1474
1474
else pt
1475
1475
1476
- def returnProto (owner : Symbol , locals : Scope ): Type =
1476
+ def returnProto (owner : Symbol ): Type =
1477
1477
if (owner.isConstructor) defn.UnitType
1478
1478
else
1479
- val rt = owner.info match
1479
+ // We need to get the return type of the enclosing function, with all parameters replaced
1480
+ // by the local type and value parameters. It would be nice if we could look up that
1481
+ // type simply in the tpt field of the enclosing function. But the tree argument in
1482
+ // a context is an untyped tree, so we cannot extract its type.
1483
+ def instantiateRT (info : Type , psymss : List [List [Symbol ]]): Type = info match
1480
1484
case info : PolyType =>
1481
- val tparams = locals.toList.takeWhile(_ is TypeParam )
1482
- assert(info.paramNames.length == tparams.length,
1483
- i " return mismatch from $owner, tparams = $tparams, locals = ${locals.toList}%, % " )
1484
- info.instantiate(tparams.map(_.typeRef)).finalResultType
1485
+ instantiateRT(info.instantiate(psymss.head.map(_.typeRef)), psymss.tail)
1486
+ case info : MethodType =>
1487
+ instantiateRT(info.instantiate(psymss.head.map(_.termRef)), psymss.tail)
1485
1488
case info =>
1486
- info.finalResultType
1489
+ info.widenExpr
1490
+ val rt = instantiateRT(owner.info, owner.paramSymss)
1487
1491
def iftParamss = ctx.owner.ownersIterator
1488
1492
.filter(_.is(Method , butNot = Accessor ))
1489
1493
.takeWhile(_.isAnonymousFunction)
@@ -1505,7 +1509,7 @@ class Typer extends Namer
1505
1509
(EmptyTree , errorType(MissingReturnTypeWithReturnStatement (owner), tree.sourcePos))
1506
1510
else {
1507
1511
val from = Ident (TermRef (NoPrefix , owner.asTerm))
1508
- val proto = returnProto(owner, cx.scope )
1512
+ val proto = returnProto(owner)
1509
1513
(from, proto)
1510
1514
}
1511
1515
else enclMethInfo(cx.outer)
0 commit comments