Skip to content

Commit 8b14802

Browse files
committed
Avoid spurious dealiasing in alignDependentFunction
This would become a problem when adding fluid capture sets to FromJavaObject types. And it anyway gives better error messages.
1 parent 4a84557 commit 8b14802

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,10 @@ class CheckCaptures extends Recheck, SymTransformer:
642642
/** Turn `expected` into a dependent function when `actual` is dependent. */
643643
private def alignDependentFunction(expected: Type, actual: Type)(using Context): Type =
644644
def recur(expected: Type): Type = expected.dealias match
645-
case expected @ CapturingType(eparent, refs) =>
646-
CapturingType(recur(eparent), refs, boxed = expected.isBoxed)
645+
case expected0 @ CapturingType(eparent, refs) =>
646+
val eparent1 = recur(eparent)
647+
if eparent1 eq eparent then expected
648+
else CapturingType(eparent1, refs, boxed = expected0.isBoxed)
647649
case expected @ defn.FunctionOf(args, resultType, isContextual)
648650
if defn.isNonRefinedFunction(expected) && defn.isFunctionType(actual) && !defn.isNonRefinedFunction(actual) =>
649651
val expected1 = toDepFun(args, resultType, isContextual)

tests/neg-custom-args/captures/i15772.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
33 | val boxed2 : Observe[C]^ = box2(c) // error
1717
| ^^^^^^^
1818
| Found: (C{val arg: C^}^ => Unit) ->? Unit
19-
| Required: (C => Unit) => Unit
19+
| Required: Observe[C]^
2020
|
2121
| longer explanation available when compiling with `-explain`
2222
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:44:2 ----------------------------------------

0 commit comments

Comments
 (0)