@@ -1669,77 +1669,35 @@ class Typer extends Namer
1669
1669
caseRest(using ctx.fresh.setFreshGADTBounds.setNewScope)
1670
1670
}
1671
1671
1672
- def typedReturn (tree : untpd.Return )(using Context ): Return = {
1672
+ def typedReturn (tree : untpd.Return )(using Context ): Return =
1673
1673
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 ) =
1712
1675
val owner = cx.owner
1713
- if ( owner.isType) {
1676
+ if owner.isType then
1714
1677
report.error(ReturnOutsideMethodDefinition (owner), tree.srcPos)
1715
1678
(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
1719
1681
(EmptyTree , errorType(NoReturnFromInlineable (owner), tree.srcPos))
1720
- else if ( ! owner.isCompleted)
1682
+ else if ! owner.isCompleted then
1721
1683
(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)
1727
1686
else enclMethInfo(cx.outer)
1728
- }
1687
+
1729
1688
val (from, proto) =
1730
- if ( tree.from.isEmpty) enclMethInfo(ctx)
1731
- else {
1689
+ if tree.from.isEmpty then enclMethInfo(ctx)
1690
+ else
1732
1691
val from = tree.from.asInstanceOf [tpd.Tree ]
1733
1692
val proto =
1734
1693
if (ctx.erasedTypes) from.symbol.info.finalResultType
1735
1694
else WildcardType // We cannot reliably detect the internal type view of polymorphic or dependent methods
1736
1695
// because we do not know the internal type params and method params.
1737
1696
// Hence no adaptation is possible, and we assume WildcardType as prototype.
1738
1697
(from, proto)
1739
- }
1740
1698
val expr1 = typedExpr(tree.expr orElse untpd.unitLiteral.withSpan(tree.span), proto)
1741
1699
assignType(cpy.Return (tree)(expr1, from))
1742
- }
1700
+ end typedReturn
1743
1701
1744
1702
def typedWhileDo (tree : untpd.WhileDo )(using Context ): Tree =
1745
1703
inContext(Nullables .whileContext(tree.span)) {
0 commit comments