Skip to content

Commit 516df7c

Browse files
committed
Fix existential mapping of non-dependent impure function aliases =>
There was a forgotten case.
1 parent 5ade6a4 commit 516df7c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ object Existential:
315315
case t @ CapturingType(parent, refs: CaptureSet.Var) =>
316316
if variance > 0 then needsWrap = true
317317
super.mapOver(t)
318+
case defn.FunctionNOf(args, res, contextual) if t.typeSymbol.name.isImpureFunction =>
319+
if variance > 0 then
320+
needsWrap = true
321+
super.mapOver:
322+
defn.FunctionNOf(args, res, contextual).capturing(boundVar.singletonCaptureSet)
323+
else mapOver(t)
318324
case _ =>
319325
mapOver(t)
320326
//.showing(i"mapcap $t = $result")
@@ -341,6 +347,7 @@ object Existential:
341347
case res: MethodType => mapFunOrMethod(res, res.paramInfos, res.resType)
342348
case res: PolyType => mapFunOrMethod(res, Nil, res.resType) // TODO: Also map bounds of PolyTypes
343349
case _ => mapCap(apply(res), fail)
350+
//.showing(i"map cap res $res / ${apply(res)} of $tp = $result")
344351
tp.derivedFunctionOrMethod(args1, res1)
345352

346353
def apply(t: Type): Type = t match

tests/neg/existential-mapping.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@
6868
-- [E007] Type Mismatch Error: tests/neg/existential-mapping.scala:36:25 -----------------------------------------------
6969
36 | val _: A^ => C^ => C = y4 // error
7070
| ^^
71-
| Found: (y4 : A^ => C^ => (ex$52: caps.Exists) -> C^{ex$52})
72-
| Required: A^ => C^ => C
71+
| Found: (y4 : A^ => (ex$53: caps.Exists) -> C^ ->{ex$53} (ex$52: caps.Exists) -> C^{ex$52})
72+
| Required: A^ => (ex$56: caps.Exists) -> C^ ->{ex$56} C
7373
|
7474
| longer explanation available when compiling with `-explain`
7575
-- [E007] Type Mismatch Error: tests/neg/existential-mapping.scala:39:30 -----------------------------------------------
7676
39 | val _: A^ => (x: C^) -> C = y5 // error
7777
| ^^
78-
| Found: (y5 : A^ => (ex$60: caps.Exists) -> Fun[C^{ex$60}])
78+
| Found: (y5 : A^ => (ex$58: caps.Exists) -> Fun[C^{ex$58}])
7979
| Required: A^ => (x: C^) -> C
8080
|
8181
| longer explanation available when compiling with `-explain`
8282
-- [E007] Type Mismatch Error: tests/neg/existential-mapping.scala:42:30 -----------------------------------------------
8383
42 | val _: A^ => (x: C^) => C = y6 // error
8484
| ^^
85-
| Found: (y6 : A^ => (ex$66: caps.Exists) -> IFun[C^{ex$66}])
86-
| Required: A^ => (ex$69: caps.Exists) -> (x: C^) ->{ex$69} C
85+
| Found: (y6 : A^ => (ex$64: caps.Exists) -> IFun[C^{ex$64}])
86+
| Required: A^ => (ex$67: caps.Exists) -> (x: C^) ->{ex$67} C
8787
|
8888
| longer explanation available when compiling with `-explain`

tests/neg/existential-mapping.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ def Test =
4444
val z1: A^ => Array[C^] = ??? // error
4545

4646

47-

0 commit comments

Comments
 (0)