@@ -1732,11 +1732,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1732
1732
else typedFunctionValue(tree, pt)
1733
1733
1734
1734
def typedFunctionType (tree : untpd.Function , pt : Type )(using Context ): Tree = {
1735
- val untpd .Function (args, body ) = tree
1736
- body match
1737
- case untpd.CapturesAndResult (refs, result ) =>
1735
+ val untpd .Function (args, result ) = tree
1736
+ result match
1737
+ case untpd.CapturesAndResult (refs, result1 ) =>
1738
1738
return typedUnadapted(untpd.makeRetaining(
1739
- cpy.Function (tree)(args, result ), refs, tpnme.retains), pt)
1739
+ cpy.Function (tree)(args, result1 ), refs, tpnme.retains), pt)
1740
1740
case _ =>
1741
1741
var (funFlags, erasedParams) = tree match {
1742
1742
case tree : untpd.FunctionWithMods => (tree.mods.flags, tree.erasedParams)
@@ -1748,37 +1748,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1748
1748
val isImpure = funFlags.is(Impure )
1749
1749
1750
1750
/** Typechecks dependent function type with given parameters `params` */
1751
- def typedDependent (params : List [untpd.ValDef ])(using Context ): Tree =
1752
- val fixThis = new untpd.UntypedTreeMap :
1753
- // pretype all references of this in outer context,
1754
- // so that they do not refer to the refined type being constructed
1755
- override def transform (tree : untpd.Tree )(using Context ): untpd.Tree = tree match
1756
- case This (id) => untpd.TypedSplice (typedExpr(tree)(using ctx.outer))
1757
- case _ => super .transform(tree)
1758
-
1751
+ def typedDependent (params : List [untpd.ValDef ], result : untpd.Tree )(using Context ): Tree =
1759
1752
val params1 =
1760
1753
if funFlags.is(Given ) then params.map(_.withAddedFlags(Given ))
1761
1754
else params
1762
- val params2 = params1.map(fixThis.transformSub)
1763
- val params3 = params2.zipWithConserve(erasedParams) { (arg, isErased) =>
1755
+ val params2 = params1.zipWithConserve(erasedParams): (arg, isErased) =>
1764
1756
if isErased then arg.withAddedFlags(Erased ) else arg
1765
- }
1766
- val appDef0 = untpd.DefDef (nme.apply, List (params3), body, EmptyTree ).withSpan(tree.span)
1757
+ val appDef0 = untpd.DefDef (nme.apply, List (params2), result, EmptyTree ).withSpan(tree.span)
1767
1758
index(appDef0 :: Nil )
1768
1759
val appDef = typed(appDef0).asInstanceOf [DefDef ]
1769
1760
val mt = appDef.symbol.info.asInstanceOf [MethodType ]
1770
1761
if (mt.isParamDependent)
1771
1762
report.error(em " $mt is an illegal function type because it has inter-parameter dependencies " , tree.srcPos)
1772
1763
// Restart typechecking if there are erased classes that we want to mark erased
1773
1764
if mt.erasedParams.zip(mt.paramInfos.map(_.isErasedClass)).exists((paramErased, classErased) => classErased && ! paramErased) then
1774
- val newParams = params3 .zipWithConserve(mt.paramInfos.map(_.isErasedClass)) { (arg, isErasedClass) =>
1765
+ val newParams = params2 .zipWithConserve(mt.paramInfos.map(_.isErasedClass)) { (arg, isErasedClass) =>
1775
1766
if isErasedClass then arg.withAddedFlags(Erased ) else arg
1776
1767
}
1777
- return typedDependent(newParams)
1768
+ return typedDependent(newParams, result )
1778
1769
val core =
1779
1770
if mt.hasErasedParams then TypeTree (defn.PolyFunctionClass .typeRef)
1780
1771
else
1781
- val resTpt = TypeTree (mt.nonDependentResultApprox).withSpan(body .span)
1772
+ val resTpt = TypeTree (mt.nonDependentResultApprox).withSpan(result .span)
1782
1773
val paramTpts = appDef.termParamss.head.map(p => TypeTree (p.tpt.tpe).withSpan(p.tpt.span))
1783
1774
val funSym = defn.FunctionSymbol (numArgs, isContextual)
1784
1775
val tycon = TypeTree (funSym.typeRef)
@@ -1792,19 +1783,28 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1792
1783
1793
1784
args match {
1794
1785
case ValDef (_, _, _) :: _ =>
1795
- typedDependent(args.asInstanceOf [List [untpd.ValDef ]])(
1786
+ val fixThis = new untpd.UntypedTreeMap :
1787
+ // pretype all references of this so that they do not refer to the
1788
+ // refined type being constructed
1789
+ override def transform (tree : untpd.Tree )(using Context ): untpd.Tree = tree match
1790
+ case This (id) => untpd.TypedSplice (typedExpr(tree))
1791
+ case _ => super .transform(tree)
1792
+
1793
+ val untpd .Function (fixedArgs : List [untpd.ValDef ] @ unchecked, fixedResult) =
1794
+ fixThis.transform(tree): @ unchecked
1795
+ typedDependent(fixedArgs, fixedResult)(
1796
1796
using ctx.fresh.setOwner(newRefinedClassSymbol(tree.span)).setNewScope)
1797
1797
case _ =>
1798
1798
if erasedParams.contains(true ) then
1799
1799
typedFunctionType(desugar.makeFunctionWithValDefs(tree, pt), pt)
1800
1800
else
1801
1801
val funSym = defn.FunctionSymbol (numArgs, isContextual, isImpure)
1802
- val result = typed(cpy.AppliedTypeTree (tree)(untpd.TypeTree (funSym.typeRef), args :+ body ), pt)
1802
+ val funTpt = typed(cpy.AppliedTypeTree (tree)(untpd.TypeTree (funSym.typeRef), args :+ result ), pt)
1803
1803
// if there are any erased classes, we need to re-do the typecheck.
1804
- result match
1804
+ funTpt match
1805
1805
case r : AppliedTypeTree if r.args.exists(_.tpe.isErasedClass) =>
1806
1806
typedFunctionType(desugar.makeFunctionWithValDefs(tree, pt), pt)
1807
- case _ => result
1807
+ case _ => funTpt
1808
1808
}
1809
1809
}
1810
1810
0 commit comments