Skip to content

Commit c35fbe4

Browse files
committed
Freshen invariant occurrences of caps
1 parent bb4ae9c commit c35fbe4

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ object Capabilities:
693693
thisMap =>
694694

695695
override def apply(t: Type) =
696-
if variance <= 0 then t
696+
if variance < 0 then t
697697
else t match
698698
case t @ CapturingType(_, _) =>
699699
mapOver(t)
@@ -703,6 +703,8 @@ object Capabilities:
703703
this(CapturingType(parent1, ann.tree.toCaptureSet))
704704
else
705705
t.derivedAnnotatedType(parent1, ann)
706+
case t @ FunctionOrMethod(_, _) if t.isAliasFun =>
707+
t // stop at dependent function types
706708
case _ =>
707709
mapFollowingAliases(t)
708710

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
| ^
44
| Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^]
55
|
6-
| where: ^ refers to the universal root capability
6+
| where: ^ refers to a fresh root capability in the type of value foo
77
|
88
| longer explanation available when compiling with `-explain`
99
-- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:10:11 --------------------------------
1010
10 | type T = C[Tree^] // error
1111
| ^
1212
| Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^]
1313
|
14-
| where: ^ refers to the universal root capability
14+
| where: ^ refers to a fresh root capability in the type of type T
1515
|
1616
| longer explanation available when compiling with `-explain`
1717
-- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:11:11 --------------------------------

tests/neg-custom-args/captures/box-adapt-cases.check

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:8:10 -------------------------------
2-
8 | x.value(cap => cap.use()) // error, was OK
3-
| ^^^^^^^^^^^^^^^^
4-
| Found: (cap: Cap^?) => Int
5-
| Required: Cap^ =>² Int
6-
|
7-
| where: => refers to the universal root capability
8-
| =>² refers to a fresh root capability created in method test1
9-
| ^ refers to the universal root capability
10-
|
11-
| longer explanation available when compiling with `-explain`
121
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:15:10 ------------------------------
132
15 | x.value(cap => cap.use()) // error
143
| ^^^^^^^^^^^^^^^^

tests/neg-custom-args/captures/box-adapt-cases.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def test1(): Unit = {
55
class Id[X](val value: [T] -> (op: X => T) -> T)
66

77
val x: Id[Cap^] = ???
8-
x.value(cap => cap.use()) // error, was OK
8+
x.value(cap => cap.use())
99
}
1010

1111
def test2(io: Cap^): Unit = {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Error: tests/neg-custom-args/captures/class-level-attack.scala:12:24 ------------------------------------------------
2+
12 | val r: Ref[IO^] = Ref[IO^](io) // error:
3+
| ^^^
4+
| Type variable X of constructor Ref cannot be instantiated to IO^ since
5+
| that type captures the root capability `cap`.
6+
|
7+
| where: ^ refers to the universal root capability
8+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/class-level-attack.scala:17:26 ---------------------------
9+
17 | def set(x: IO^) = r.put(x) // error
10+
| ^
11+
| Found: IO^{x}
12+
| Required: IO^
13+
|
14+
| where: ^ refers to a fresh root capability in the type of value r
15+
|
16+
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/class-level-attack.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ class C(io: IO^):
1313
//Type variable X of constructor Ref cannot be instantiated to box IO^ since
1414
//that type captures the root capability `cap`.
1515
// where: ^ refers to the universal root capability
16-
val r2: Ref[IO^] = Ref(io) // error:
17-
//Error: Ref[IO^{io}] does not conform to Ref[IO^] (since Refs are invariant)
18-
def set(x: IO^) = r.put(x)
16+
val r2: Ref[IO^] = Ref(io)
17+
def set(x: IO^) = r.put(x) // error
1918

2019
def outer(outerio: IO^) =
2120
val c = C(outerio)

tests/neg-custom-args/captures/i16725.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ def usingIO[T](op: IO => T): T = ???
66
class Wrapper[T](val value: [R] -> (f: T => R) -> R)
77
def mk[T](x: T): Wrapper[T] = Wrapper([R] => f => f(x))
88
def useWrappedIO(wrapper: Wrapper[IO]): () -> Unit =
9-
() =>
10-
wrapper.value: io => // error
9+
() => // error
10+
wrapper.value: io =>
1111
io.brewCoffee()
1212
def main(): Unit =
13-
val escaped = usingIO(io => useWrappedIO(mk(io))) // error
13+
val escaped = usingIO(io => useWrappedIO(mk(io)))
1414
escaped() // boom

0 commit comments

Comments
 (0)