@@ -606,11 +606,27 @@ class CheckCaptures extends Recheck, SymTransformer:
606
606
607
607
/** Massage `actual` and `expected` types using the methods below before checking conformance */
608
608
override def checkConformsExpr (actual : Type , expected : Type , tree : Tree )(using Context ): Unit =
609
- val expected1 = addOuterRefs(expected, actual)
609
+ val expected1 = makeFunctionDependent( addOuterRefs(expected, actual), actual.stripCapturing )
610
610
val actual1 = adaptBoxed(actual, expected1, tree.srcPos)
611
611
// println(i"check conforms $actual1 <<< $expected1")
612
612
super .checkConformsExpr(actual1, expected1, tree)
613
613
614
+ private def toDepFun (args : List [Type ], resultType : Type , isContextual : Boolean , isErased : Boolean )(using Context ): Type =
615
+ MethodType .companion(isContextual = isContextual, isErased = isErased)(args, resultType)
616
+ .toFunctionType(isJava = false , alwaysDependent = true )
617
+
618
+ private def makeFunctionDependent (expected : Type , actual : Type )(using Context ): Type =
619
+ def recur (expected : Type ): Type = expected.dealias match
620
+ case expected @ CapturingType (eparent, refs) =>
621
+ CapturingType (recur(eparent), refs, boxed = expected.isBoxed)
622
+ case expected @ defn.FunctionOf (args, resultType, isContextual, isErased)
623
+ if defn.isNonRefinedFunction(expected) && defn.isFunctionType(actual) && ! defn.isNonRefinedFunction(actual) =>
624
+ val expected1 = toDepFun(args, resultType, isContextual, isErased)
625
+ expected1
626
+ case _ =>
627
+ expected
628
+ recur(expected)
629
+
614
630
/** For the expected type, implement the rule outlined in #14390:
615
631
* - when checking an expression `a: Ca Ta` against an expected type `Ce Te`,
616
632
* - where the capture set `Ce` contains Cls.this,
0 commit comments