Skip to content

Commit cfe4fcf

Browse files
committed
Make sure FunctionOf does not match result-depenedent fucntions
1 parent 05593cb commit cfe4fcf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ class CheckCaptures extends Recheck, SymTransformer:
501501
override def recheckBlock(block: Block, pt: Type)(using Context): Type =
502502
block match
503503
case closureDef(mdef) =>
504-
pt.dealias match
505-
case defn.FunctionOf(ptformals, _, _)
506-
if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) =>
504+
def recheckFunction(ptformals: List[Type]) =
505+
if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) then
507506
// Redo setup of the anonymous function so that formal parameters don't
508507
// get capture sets. This is important to avoid false widenings to `cap`
509508
// when taking the base type of the actual closures's dependent function
@@ -531,6 +530,9 @@ class CheckCaptures extends Recheck, SymTransformer:
531530
.showing(i"simplify info of $meth to $result", capt)
532531
recheckDef(mdef, meth)
533532
meth.updateInfoBetween(preRecheckPhase, thisPhase, completer)
533+
pt.dealias match
534+
case defn.FunctionOf(ptformals, _, _) => recheckFunction(ptformals)
535+
case defn.DependentFunctionRefinementOf(_, mt) => recheckFunction(mt.paramInfos)
534536
case _ =>
535537
mdef.rhs match
536538
case rhs @ closure(_, _, _) =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,11 @@ class Definitions {
11221122

11231123
/** Matches a (possibly aliased) `FunctionN[...]`, `ContextFunctionN[...]` or refined `PolyFunction`.
11241124
* Extracts the list of function argument types, the result type and whether function is contextual.
1125+
* It only matches a `PolyFunction` if the function type is not result dependent.
11251126
*/
11261127
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
11271128
ft.dealias match
1128-
case PolyFunctionOf(mt: MethodType) =>
1129+
case PolyFunctionOf(mt: MethodType) if !mt.isResultDependent =>
11291130
Some(mt.paramInfos, mt.resType, mt.isContextualMethod)
11301131
case FunctionNOf(targs, resType, isContextual) =>
11311132
Some(targs, resType, isContextual)

0 commit comments

Comments
 (0)