@@ -1669,77 +1669,35 @@ class Typer extends Namer
16691669 caseRest(using ctx.fresh.setFreshGADTBounds.setNewScope)
16701670 }
16711671
1672- def typedReturn (tree : untpd.Return )(using Context ): Return = {
1672+ def typedReturn (tree : untpd.Return )(using Context ): Return =
16731673
1674- /** If `pt` is a context function type, its return type. If the CFT
1675- * is dependent, instantiate with the parameters of the associated
1676- * anonymous function.
1677- * @param paramss the parameters of the anonymous functions
1678- * enclosing the return expression
1679- */
1680- def instantiateCFT (pt : Type , paramss : => List [List [Symbol ]]): Type =
1681- val ift = defn.asContextFunctionType(pt)
1682- if ift.exists then
1683- ift.nonPrivateMember(nme.apply).info match
1684- case appType : MethodType =>
1685- instantiateCFT(appType.instantiate(paramss.head.map(_.termRef)), paramss.tail)
1686- else pt
1687-
1688- def returnProto (owner : Symbol ): Type =
1689- if (owner.isConstructor) defn.UnitType
1690- else
1691- // We need to get the return type of the enclosing function, with all parameters replaced
1692- // by the local type and value parameters. It would be nice if we could look up that
1693- // type simply in the tpt field of the enclosing function. But the tree argument in
1694- // a context is an untyped tree, so we cannot extract its type.
1695- def instantiateRT (info : Type , psymss : List [List [Symbol ]]): Type = info match
1696- case info : PolyType =>
1697- instantiateRT(info.instantiate(psymss.head.map(_.typeRef)), psymss.tail)
1698- case info : MethodType =>
1699- instantiateRT(info.instantiate(psymss.head.map(_.termRef)), psymss.tail)
1700- case info =>
1701- info.widenExpr
1702- val rt = instantiateRT(owner.info, owner.paramSymss)
1703- def iftParamss = ctx.owner.ownersIterator
1704- .filter(_.is(Method , butNot = Accessor ))
1705- .takeWhile(_.isAnonymousFunction)
1706- .toList
1707- .reverse
1708- .map(_.paramSymss.head)
1709- instantiateCFT(rt, iftParamss)
1710-
1711- def enclMethInfo (cx : Context ): (Tree , Type ) = {
1674+ def enclMethInfo (cx : Context ): (Tree , Type ) =
17121675 val owner = cx.owner
1713- if ( owner.isType) {
1676+ if owner.isType then
17141677 report.error(ReturnOutsideMethodDefinition (owner), tree.srcPos)
17151678 (EmptyTree , WildcardType )
1716- }
1717- else if (owner != cx.outer.owner && owner.isRealMethod)
1718- if (owner.isInlineMethod)
1679+ else if owner != cx.outer.owner && owner.isRealMethod then
1680+ if owner.isInlineMethod then
17191681 (EmptyTree , errorType(NoReturnFromInlineable (owner), tree.srcPos))
1720- else if ( ! owner.isCompleted)
1682+ else if ! owner.isCompleted then
17211683 (EmptyTree , errorType(MissingReturnTypeWithReturnStatement (owner), tree.srcPos))
1722- else {
1723- val from = Ident (TermRef (NoPrefix , owner.asTerm))
1724- val proto = returnProto(owner)
1725- (from, proto)
1726- }
1684+ else
1685+ (Ident (TermRef (NoPrefix , owner.asTerm)), owner.returnProto)
17271686 else enclMethInfo(cx.outer)
1728- }
1687+
17291688 val (from, proto) =
1730- if ( tree.from.isEmpty) enclMethInfo(ctx)
1731- else {
1689+ if tree.from.isEmpty then enclMethInfo(ctx)
1690+ else
17321691 val from = tree.from.asInstanceOf [tpd.Tree ]
17331692 val proto =
17341693 if (ctx.erasedTypes) from.symbol.info.finalResultType
17351694 else WildcardType // We cannot reliably detect the internal type view of polymorphic or dependent methods
17361695 // because we do not know the internal type params and method params.
17371696 // Hence no adaptation is possible, and we assume WildcardType as prototype.
17381697 (from, proto)
1739- }
17401698 val expr1 = typedExpr(tree.expr orElse untpd.unitLiteral.withSpan(tree.span), proto)
17411699 assignType(cpy.Return (tree)(expr1, from))
1742- }
1700+ end typedReturn
17431701
17441702 def typedWhileDo (tree : untpd.WhileDo )(using Context ): Tree =
17451703 inContext(Nullables .whileContext(tree.span)) {
0 commit comments