Skip to content

Commit 8f87eef

Browse files
committed
Require cap to be imported from caps.
Since it is never necessary to write `cap` explicitly, there's no need to treat the identifier as a soft keyword.
1 parent 510d854 commit 8f87eef

25 files changed

+45
-45
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,15 +1474,13 @@ object Parsers {
14741474
*/
14751475
def captureRef(): Tree =
14761476
if in.token == THIS then simpleRef()
1477-
else termIdent() match
1478-
case id @ Ident(nme.CAPTURE_ROOT) =>
1479-
atSpan(id.span.start)(captureRoot)
1480-
case id =>
1481-
if isIdent(nme.raw.STAR) then
1482-
in.nextToken()
1483-
atSpan(startOffset(id)):
1484-
Select(id, nme.CC_REACH)
1485-
else id
1477+
else
1478+
val id = termIdent()
1479+
if isIdent(nme.raw.STAR) then
1480+
in.nextToken()
1481+
atSpan(startOffset(id)):
1482+
Select(id, nme.CC_REACH)
1483+
else id
14861484

14871485
/** CaptureSet ::= `{` CaptureRef {`,` CaptureRef} `}` -- under captureChecking
14881486
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ def test1(): Unit = {
77
x(cap => cap.use()) // was error, now OK
88
}
99

10-
def test2(io: Cap^{cap}): Unit = {
10+
def test2(io: Cap^): Unit = {
1111
type Id[X] = [T] -> (op: X -> T) -> T
1212

1313
val x: Id[Cap^{io}] = ???
1414
x(cap => cap.use()) // error
1515
}
1616

17-
def test3(io: Cap^{cap}): Unit = {
17+
def test3(io: Cap^): Unit = {
1818
type Id[X] = [T] -> (op: X ->{io} T) -> T
1919

2020
val x: Id[Cap^{io}] = ???
2121
x(cap => cap.use()) // ok
2222
}
2323

24-
def test4(io: Cap^{cap}, fs: Cap^{cap}): Unit = {
24+
def test4(io: Cap^, fs: Cap^): Unit = {
2525
type Id[X] = [T] -> (op: X ->{io} T) -> T
2626

2727
val x: Id[Cap^{io, fs}] = ???

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ def test2(c: Cap^, d: Cap^): Unit =
1515
val f2: (Cap^{c} -> Unit) ->{c} Unit = useCap2[Cap^{c}](c) // ok
1616

1717
def useCap3[X](x: X): (X ->{d} Unit) -> Unit = ???
18-
val f3: (Cap^{c} -> Unit) ->{cap} Unit = useCap3[Cap^{c}](c) // error
18+
val f3: (Cap^{c} -> Unit) => Unit = useCap3[Cap^{c}](c) // error

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
trait Cap
22

3-
def test1(io: Cap^{cap}) = {
3+
def test1(io: Cap^) = {
44
type Op[X] = [T] -> Unit -> X
55
val f: Op[Cap^{io}] = ???
66
val x: [T] -> Unit -> Cap^{io} = f // error
77
}
88

9-
def test2(io: Cap^{cap}) = {
9+
def test2(io: Cap^) = {
1010
type Op[X] = [T] -> Unit -> X^{io}
1111
val f: Op[Cap^{io}] = ???
1212
val x: Unit -> Cap^{io} = f[Unit] // error

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
trait Cap { def use(): Int }
22

3-
def test1(io: Cap^{cap}): Unit = {
3+
def test1(io: Cap^): Unit = {
44
type Id[X] = [T] -> (op: X ->{io} T) -> T
55

66
val x: Id[Cap^{io}] = ???
7-
val f: (Cap^{cap}) -> Unit = ???
7+
val f: (Cap^) -> Unit = ???
88
x(f) // ok
99
}
1010

11-
def test2(io: Cap^{cap}): Unit = {
11+
def test2(io: Cap^): Unit = {
1212
type Id[X] = [T] -> (op: X => T) -> T
1313

1414
val x: Id[Cap^] = ???

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test2(io: Cap^): Unit = {
1515
// should work when the expected type is a dependent function
1616
}
1717

18-
def test3(io: Cap^{cap}): Unit = {
18+
def test3(io: Cap^): Unit = {
1919
type Id[X] = [T] -> (op: (x: X) ->{} T) -> T
2020

2121
val x: Id[Cap^{io}] = ???

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
trait Cap { def use(): Int }
22

3-
def test1(io: Cap^{cap}): Unit = {
3+
def test1(io: Cap^): Unit = {
44
type Op[X] = [T] -> X -> Unit
55
val f: [T] -> (Cap^{io}) -> Unit = ???
66
val op: Op[Cap^{io}] = f // error
77
}
88

9-
def test2(io: Cap^{cap}): Unit = {
9+
def test2(io: Cap^): Unit = {
1010
type Lazy[X] = [T] -> Unit -> X
1111
val f: Lazy[Cap^{io}] = ???
1212
val test: [T] -> Unit -> (Cap^{io}) = f // error

tests/neg-custom-args/captures/cc-glb.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ trait Cap
33
trait Foo[+T]
44

55
def magic[T](io: Cap^, x: Foo[T]^{io}): Foo[T]^{} =
6-
val x1: Foo[T]^{cap} & Foo[Any]^{io} = x
6+
val x1: (Foo[T]^) & Foo[Any]^{io} = x
77
val x2: Foo[T] = x1 // error
88
x2 // boom, an impure value becomes pure

tests/neg-custom-args/captures/heal-tparam-cs.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import language.experimental.captureChecking
22

33
trait Capp { def use(): Unit }
44

5-
def localCap[sealed T](op: (c: Capp^{cap}) => T): T = ???
5+
def localCap[sealed T](op: (c: Capp^) => T): T = ???
66

7-
def main(io: Capp^{cap}, net: Capp^{cap}): Unit = {
7+
def main(io: Capp^, net: Capp^): Unit = {
88

99
val test1 = localCap { c => // error
1010
() => { c.use() }
1111
}
1212

13-
val test2: (c: Capp^{cap}) -> () ->{cap} Unit =
13+
val test2: (c: Capp^) -> () => Unit =
1414
localCap { c => // should work
15-
(c1: Capp^{cap}) => () => { c1.use() }
15+
(c1: Capp^) => () => { c1.use() }
1616
}
1717

1818
val test3: (c: Capp^{io}) -> () ->{io} Unit =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Session:
22
def request = "Response"
33
class Foo:
4-
private val session: Session^{cap} = new Session
4+
private val session: Session^ = new Session
55
def withSession[sealed T](f: Session^ => T): T = f(session)
66

77
def Test: Unit =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def withCap[T](op: Cap^ => T): T = {
1111
}
1212

1313
def main(fs: Cap^): Unit = {
14-
def badOp(io: Cap^{cap}): Unit ->{} Unit = {
14+
def badOp(io: Cap^): Unit ->{} Unit = {
1515
val op1: Unit ->{io} Unit = (x: Unit) =>
1616
expect[Cap^] {
1717
io.use()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class CC
2-
type Cap = CC^{cap}
2+
type Cap = CC^
33

44
trait LazyList[+A]:
5-
this: LazyList[A]^{cap} =>
5+
this: LazyList[A]^ =>
66

77
def isEmpty: Boolean
88
def head: A
@@ -13,7 +13,7 @@ object LazyNil extends LazyList[Nothing]:
1313
def head = ???
1414
def tail = ???
1515

16-
extension [A](xs: LazyList[A]^{cap})
16+
extension [A](xs: LazyList[A]^)
1717
def map[B](f: A => B): LazyList[B]^{xs, f} =
1818
final class Mapped extends LazyList[B]:
1919
this: (Mapped^{xs, f}) =>

tests/neg-custom-args/captures/leaked-curried.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Cap:
44
def withCap[T](op: (x: Cap^) => T): T = ???
55

66
trait Box:
7-
val get: () ->{} () ->{cap} Cap^
7+
val get: () ->{} () => Cap^
88

99
def main(): Unit =
1010
val leaked = withCap: (io: Cap^) =>

tests/neg-custom-args/captures/override-adapt-box-selftype.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Test1 {
1515
}
1616
}
1717

18-
def Test2(io: IO^{cap}, fs: IO^{io}, ct: IO^) = {
18+
def Test2(io: IO^, fs: IO^{io}, ct: IO^) = {
1919
abstract class A[X] { this: A[X]^{io} =>
2020
def foo(x: X): X
2121
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ abstract class A[X] { this: A[X]^{} =>
77
class IO
88
class C
99

10-
def test(io: IO^{cap}) = {
10+
def test(io: IO^) = {
1111
class B extends A[C^{io}] { // X =:= {io} C // error
1212
override def foo(x: C^{io}): C^{io} = ???
1313
}

tests/neg-custom-args/captures/override-boxed.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
class A
33

4-
def test(x: Any^{cap}) =
4+
def test(x: Any^) =
55
abstract class Getter:
66
def get(): A^{x}
77
class PolyGetter[T <: A^{x}] extends Getter:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ val x = () => ()
33
val y1: x.type = x // ok
44
val y2: x.type^{} = x // error: singleton type cannot have capture set
55
val y3: x.type^{x} = x // error: singleton type cannot have capture set // error
6-
val y4: x.type^{cap} = x // error: singleton type cannot have capture set
6+
val y4: x.type^ = x // error: singleton type cannot have capture set

tests/neg/capt-wf.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//> using options -language:experimental.captureChecking -Xfatal-warnings
2-
2+
import caps.cap
33
class C
44
type Cap = C^
55

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import annotation.retainsByName
2+
import caps.cap
23
class CC
34
type Cap = CC^
45

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type Cap = C^
33
def f1(c: Cap): () ->{c} c.type = () => c // ok
44

55
def f2: Int =
6-
val g: Boolean ->{cap} Int = ???
6+
val g: Boolean => Int = ???
77
val x = g(true)
88
x
99

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Unit
22
object unit extends Unit
33

4-
type Top = Any^{cap}
4+
type Top = Any^
55

6-
type LazyVal[T] = Unit ->{cap} T
6+
type LazyVal[T] = Unit => T
77

88
class Foo[T](val x: T)
99

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import caps.cap
12
class Unit
23
object u extends Unit
34

tests/pos-custom-args/captures/i15923-cases.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ trait Cap { def use(): Int }
22
type Id[X] = [T] -> (op: X => T) -> T
33
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)
44

5-
def foo(x: Id[Cap^{cap}]) = {
5+
def foo(x: Id[Cap^]) = {
66
x(_.use()) // was error, now OK
77
}
88

9-
def bar(io: Cap^{cap}, x: Id[Cap^{io}]) = {
9+
def bar(io: Cap^, x: Id[Cap^{io}]) = {
1010
x(_.use())
1111
}
1212

13-
def barAlt(a: Cap^{cap}, b: Cap^{cap}, x: Id[Cap]^{a, b}) = {
13+
def barAlt(a: Cap^, b: Cap^, x: Id[Cap]^{a, b}) = {
1414
x(_.use())
1515
}

tests/pos-custom-args/captures/nested-classes-2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test1(x: (() => Unit)): Unit =
1111

1212
def test2(x1: (() => Unit), x2: (() => Unit) => Unit) =
1313
class C1(x1: (() => Unit), xx2: (() => Unit) => Unit):
14-
def c2(y1: (() => Unit), y2: (() => Unit) => Unit): C2^{cap} = C2(y1, y2)
14+
def c2(y1: (() => Unit), y2: (() => Unit) => Unit): C2^ = C2(y1, y2)
1515
class C2(y1: (() => Unit), y2: (() => Unit) => Unit):
1616
val a: (() => Unit) => (() => Unit) = f(y1)
1717
a(x1) //OK, but should be error

tests/pos/boxmap-paper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def lazyMap[A, B](c: Cell[A])(f: A => B): () ->{f} Cell[B]
1919
trait IO:
2020
def print(s: String): Unit
2121

22-
def test(io: IO^{cap}) =
22+
def test(io: IO^) =
2323

2424
val loggedOne: () ->{io} Int = () => { io.print("1"); 1 }
2525

0 commit comments

Comments
 (0)