@@ -1473,17 +1473,21 @@ class Typer extends Namer
14731473 instantiateCFT(appType.instantiate(paramss.head.map(_.termRef)), paramss.tail)
14741474 else pt
14751475
1476- def returnProto (owner : Symbol , locals : Scope ): Type =
1476+ def returnProto (owner : Symbol ): Type =
14771477 if (owner.isConstructor) defn.UnitType
14781478 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
14801484 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)
14851488 case info =>
1486- info.finalResultType
1489+ info.widenExpr
1490+ val rt = instantiateRT(owner.info, owner.paramSymss)
14871491 def iftParamss = ctx.owner.ownersIterator
14881492 .filter(_.is(Method , butNot = Accessor ))
14891493 .takeWhile(_.isAnonymousFunction)
@@ -1505,7 +1509,7 @@ class Typer extends Namer
15051509 (EmptyTree , errorType(MissingReturnTypeWithReturnStatement (owner), tree.sourcePos))
15061510 else {
15071511 val from = Ident (TermRef (NoPrefix , owner.asTerm))
1508- val proto = returnProto(owner, cx.scope )
1512+ val proto = returnProto(owner)
15091513 (from, proto)
15101514 }
15111515 else enclMethInfo(cx.outer)
0 commit comments