Skip to content

Commit 65c9929

Browse files
committed
Do not capture dependent function refinements in ContextFunctionOf
1 parent 2eb722e commit 65c9929

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,8 @@ class Definitions {
11381138
asContextFunctionType(tp) match
11391139
case PolyFunctionOf(mt: MethodType) =>
11401140
Some((mt.paramInfos, mt.resType))
1141+
case DependentFunctionRefinementOf(_, mt) =>
1142+
None
11411143
case tp1 if tp1.exists =>
11421144
val args = tp1.functionArgInfos
11431145
val erasedParams = List.fill(functionArity(tp1)) { false }

compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ object ContextFunctionResults:
2020
*/
2121
def annotateContextResults(mdef: DefDef)(using Context): Unit =
2222
def contextResultCount(rhs: Tree, tp: Type): Int = tp match
23+
case defn.DependentFunctionRefinementOf(_, mt) if mt.isContextualMethod =>
24+
rhs match
25+
case closureDef(meth) => 1 + contextResultCount(meth.rhs, mt.resType)
26+
case _ => 0
2327
case defn.ContextFunctionOf(_, resTpe) =>
2428
rhs match
2529
case closureDef(meth) => 1 + contextResultCount(meth.rhs, resTpe)
@@ -58,6 +62,8 @@ object ContextFunctionResults:
5862
*/
5963
def contextResultsAreErased(sym: Symbol)(using Context): Boolean =
6064
def allErased(tp: Type): Boolean = tp.dealias match
65+
case ft @ defn.DependentFunctionRefinementOf(_, mt) if mt.isContextualMethod =>
66+
!defn.erasedFunctionParams(ft).contains(false) && allErased(mt.resType)
6167
case ft @ defn.ContextFunctionOf(_, resTpe) =>
6268
!defn.erasedFunctionParams(ft).contains(false) && allErased(resTpe)
6369
case _ => true
@@ -73,6 +79,8 @@ object ContextFunctionResults:
7379
integrateContextResults(rt, crCount)
7480
case tp: MethodOrPoly =>
7581
tp.derivedLambdaType(resType = integrateContextResults(tp.resType, crCount))
82+
case defn.DependentFunctionRefinementOf(base, mt) if mt.isContextualMethod =>
83+
integrateContextResults(base, crCount)
7684
case defn.ContextFunctionOf(argTypes, resType) =>
7785
MethodType(argTypes, integrateContextResults(resType, crCount - 1))
7886

@@ -120,6 +128,8 @@ object ContextFunctionResults:
120128
case Select(qual, name) =>
121129
if name == nme.apply then
122130
qual.tpe match
131+
case defn.DependentFunctionRefinementOf(_, mt) if mt.isContextualMethod =>
132+
integrateSelect(qual, n + 1)
123133
case defn.ContextFunctionOf(_, _) =>
124134
integrateSelect(qual, n + 1)
125135
case _ if defn.isContextFunctionClass(tree.symbol.maybeOwner) => // for TermRefs

0 commit comments

Comments
 (0)