Skip to content

Commit f3c2c04

Browse files
committed
Always requires hats on capture var definitions
1 parent f08210d commit f3c2c04

13 files changed

+59
-61
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ class Namer { typer: Typer =>
11321132
ensureUpToDate(sym.typeRef, dummyInfo1)
11331133
if (dummyInfo2 `ne` dummyInfo1) ensureUpToDate(sym.typeRef, dummyInfo2)
11341134

1135-
if sym.info.derivesFrom(defn.Caps_CapSet) then
1135+
if original.hasAttachment(Trees.CaptureVar) then
11361136
addDummyTermCaptureParam(sym)(using ictx)
11371137

11381138
sym.info

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main() =
1111
def log(msg: String): Unit
1212

1313
// we can close over anything subsumed by the 'trusted' brand capability, but nothing else
14-
def runSecure[C >: {trusted} <: {trusted}](block: () ->{C} Unit): Unit = block()
14+
def runSecure[C^ >: {trusted} <: {trusted}](block: () ->{C} Unit): Unit = block()
1515

1616
// This is a 'brand" capability to mark what can be mentioned in trusted code
1717
object trusted extends caps.Capability

tests/neg-custom-args/captures/capset-bound.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ case class File(io: IO^)
77

88
def test(io1: IO^, io2: IO^) =
99
def f[C^ >: {io1}](file: File^{C}) = ???
10-
def g[C >: {io1}](file: File^{C}) = ???
1110
val f1: File^{io1} = ???
1211
val f2: File^{io2} = ???
1312
val f3: File^{io1, io2} = ???
@@ -17,11 +16,4 @@ def test(io1: IO^, io2: IO^) =
1716
f[{io2}](f2) // error
1817
f[{io1, io2}](f1)
1918
f[{io1, io2}](f2)
20-
f[{io1, io2}](f3)
21-
g[{io1}](f1)
22-
g[{io1}](f2) // error
23-
g[{io1}](f3) // error
24-
g[{io2}](f2) // error
25-
g[{io1, io2}](f1)
26-
g[{io1, io2}](f2)
27-
g[{io1, io2}](f3)
19+
f[{io1, io2}](f3)

tests/neg-custom-args/captures/capset-members-nohat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import language.experimental.captureChecking
22
import caps.*
33

44
trait Abstract[X^]:
5-
type C >: {X}
5+
type C^ >: {X}
66
// Don't test the return type using Unit, because it is a pure type.
77
def boom(): AnyRef^{C}
88

tests/neg-custom-args/captures/capset-members4.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test =
88
def onlyWithZ[C^](using c: Contains[C, z.type]) = ???
99

1010
trait Foo:
11-
type C >: {z,x} <: {x,y,z}
11+
type C^ >: {z,x} <: {x,y,z}
1212

1313
val foo: Foo = ???
1414
onlyWithZ[{foo.C}]

tests/neg-custom-args/captures/capset-members5.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ def test =
1010
val z: Any^ = ???
1111
trait CaptureSet:
1212
type A^ >: {y} <: {x}
13-
type B = {x}
14-
type C <: {x}
13+
type B^ = {x}
14+
type C^ <: {x}
1515
type D^ : Ctx // error
16-
type E <: {C}
17-
type F <: {C}
18-
type G <: {x, y}
19-
type H >: {x} <: {x,y} : Ctx // error
16+
type E^ <: {C}
17+
type F^ <: {C}
18+
type G^ <: {x, y}
19+
type H^ >: {x} <: {x,y} : Ctx // error
2020
type I^ = {y, G, H}
2121
type J = {O.z}
2222
type K^ = {x, O.z}
23-
type L <: {x, y, O.z}
24-
type M >: {x, y, O.z} <: {C}
25-
type N >: {x} <: {x}
26-
type O >: {O.z} <: {O.z}
27-
type P >: {B,D} // error
28-
type Q >: {E} <: Int // error
23+
type L^ <: {x, y, O.z}
24+
type M^ >: {x, y, O.z} <: {C}
25+
type N^ >: {x} <: {x}
26+
type O^ >: {O.z} <: {O.z}
27+
type P^ >: {B,D} // error
28+
type Q^ >: {E} <: Int // error
2929
type R^ >: {E} <: Int // error
3030
type S^ >: Nothing <: Int // error
3131
type T >: Nothing <: Int

tests/neg-custom-args/captures/capture-parameters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import caps.*
22

33
class C
44

5-
def test[X^, Y^, Z >: X <: Y](x: C^{X}, y: C^{Y}, z: C^{Z}) =
5+
def test[X^, Y^, Z^ >: X <: Y](x: C^{X}, y: C^{Y}, z: C^{Z}) =
66
val x2z: C^{Z} = x
77
val z2y: C^{Y} = z
88
val x2y: C^{Y} = x // error

tests/pos-custom-args/captures/cap-paramlist8-desugared.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
val z: Any^{cap} = ???
1212
}
1313
val baz3:
14-
Int -> [C >: caps.CapSet <: caps.CapSet^,
15-
D >: caps.CapSet <: caps.CapSet^{C}, E >: caps.CapSet <:
16-
caps.CapSet^{C, x}] => () -> [F >: caps.CapSet^{x, y} <:
14+
Int -> [C^ >: caps.CapSet <: caps.CapSet^,
15+
D^ >: caps.CapSet <: caps.CapSet^{C}, E^ >: caps.CapSet <:
16+
caps.CapSet^{C, x}] => () -> [F^ >: caps.CapSet^{x, y} <:
1717
caps.CapSet^{C, E}] => (x: Int) -> (Ctx[F]) ?-> Int
1818
= (i: Int) => [
19-
C >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{cap},
20-
D >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{C},
21-
E >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{C, x}] =>
19+
C^ >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{cap},
20+
D^ >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{C},
21+
E^ >: _root_.scala.caps.CapSet <: _root_.scala.caps.CapSet^{C, x}] =>
2222
() => [
2323
F
2424
>: _root_.scala.caps.CapSet^{x, y} <:

tests/pos-custom-args/captures/cap-paramlists.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ def test =
55
val y: Any^ = ???
66
object O:
77
val z: Any^ = ???
8-
def foo[A >: {y} <: {x},
8+
def foo[A^ >: {y} <: {x},
99
B^,
10-
C <: {x},
10+
C^ <: {x},
1111
D^,
12-
E <: {C},
13-
F <: {C},
14-
G <: {x, y},
15-
H >: {x} <: {x,y}, T, U >: {x}]()[I^ <: {y, G, H},
16-
J <: {O.z},
17-
K <: {x, O.z},
18-
L <: {x, y, O.z},
19-
M >: {x, y, O.z} <: {C},
20-
N >: {x} <: {x},
21-
O >: {O.z} <: {O.z}] = ???
12+
E^ <: {C},
13+
F^ <: {C},
14+
G^ <: {x, y},
15+
H^ >: {x} <: {x,y}, T, U >: {x}]()[I^ <: {y, G, H},
16+
J^ <: {O.z},
17+
K^ <: {x, O.z},
18+
L^ <: {x, y, O.z},
19+
M^ >: {x, y, O.z} <: {C},
20+
N^ >: {x} <: {x},
21+
O^ >: {O.z} <: {O.z}] = ???

tests/pos-custom-args/captures/capset-members.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ def test =
77
val z: Any^ = ???
88
trait CaptureSet:
99
type A^ >: {y} <: {x}
10-
type B = {x}
11-
type C <: {x}
10+
type B^ = {x}
11+
type C^ <: {x}
1212
type D^
13-
type E <: {C}
14-
type F <: {C}
15-
type G <: {x, y}
16-
type H >: {x} <: {x,y}
13+
type E^ <: {C}
14+
type F^ <: {C}
15+
type G^ <: {x, y}
16+
type H^ >: {x} <: {x,y}
1717
type I^ = {y, G, H}
18-
type J = {O.z}
18+
type J^ = {O.z}
1919
type K^ = {x, O.z}
20-
type L <: {x, y, O.z}
21-
type M >: {x, y, O.z} <: {C}
22-
type N >: {x} <: {x}
23-
type O >: {O.z} <: {O.z}
24-
type P >: {B,D}
20+
type L^ <: {x, y, O.z}
21+
type M^ >: {x, y, O.z} <: {C}
22+
type N^ >: {x} <: {x}
23+
type O^ >: {O.z} <: {O.z}
24+
type P^ >: {B,D}

tests/pos-custom-args/captures/i21868.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import language.experimental.captureChecking
22
import caps.*
33

44
trait AbstractWrong:
5-
type C <: CapSet // no longer an error, the lower bound becomes CapSet now
5+
type C^ <: CapSet // no longer an error, the lower bound becomes CapSet now
66
def f(): Unit^{C}
77

88
trait Abstract1:
9-
type C >: CapSet <: CapSet^
9+
type C^ >: CapSet <: CapSet^
1010
def f(): Unit^{C}
1111

1212
trait Abstract2:
13-
type C <: {cap}
13+
type C^ <: {cap}
1414
def f(): Unit^{C}

tests/pos-custom-args/captures/invariant-cc.scala.disabled renamed to tests/pos-custom-args/captures/invariant-cc.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import scala.annotation.unchecked.uncheckedVariance
33

44
trait IterableFactory[+CC[_]] extends Pure:
55

6-
// TODO: elem.type is not a singleton type
7-
86
def fill[A](n: Int)(elem: => A): CC[A]^{elem} = ???
97
def fill[A](n1: Int, n2: Int)(elem: => A): CC[(CC[A]^{elem}) @uncheckedVariance]^{elem} =
108
fill[CC[A]^{elem}](n1)(fill(n2)(elem))

tests/pos/i22257.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ type Bound5 <: FP5
2424
type Node6 = NodeK { type FBound <: Bound6 }
2525
type Bound6 <: FP6
2626
type FP6 = Fixed[Node6]
27+
28+
// type X^
29+
// type Y^
30+
// type Z >: X <: Y
31+
// val Z
32+
33+
34+
// type C <:

0 commit comments

Comments
 (0)