Skip to content

Commit 468da87

Browse files
committed
Migrate tests to new syntax
Neg test use-capset revealed that type param clauses are incorrectly parsed when a capset parameter has an annotation.
1 parent 82ed8f9 commit 468da87

28 files changed

+130
-134
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,15 +2278,10 @@ object Parsers {
22782278
inBraces(refineStatSeq())
22792279

22802280
/** TypeBounds ::= [`>:' Type] [`<:' Type]
2281-
* | `^` -- under captureChecking TODO remove
22822281
*/
22832282
def typeBounds(): TypeBoundsTree =
22842283
atSpan(in.offset):
2285-
if in.isIdent(nme.UPARROW) && Feature.ccEnabled then
2286-
in.nextToken()
2287-
makeCapsBound()
2288-
else
2289-
TypeBoundsTree(bound(SUPERTYPE), bound(SUBTYPE))
2284+
TypeBoundsTree(bound(SUPERTYPE), bound(SUBTYPE))
22902285

22912286
/** CaptureSetBounds ::= [`>:' CaptureSetOrRef ] [`<:' CaptureSetOrRef ] --- under captureChecking
22922287
*/
@@ -3568,14 +3563,16 @@ object Parsers {
35683563
in.nextToken()
35693564

35703565
def typeOrCapParam(): TypeDef =
3566+
val start = in.offset
3567+
val mods = annotsAsMods() | Param
35713568
if isCapKw then
35723569
in.nextToken()
3573-
capParam()
3574-
else typeParam()
3570+
capParam(start, mods)
3571+
else typeParam(start, mods)
35753572

3576-
def capParam(): TypeDef = {
3577-
val start = in.offset
3578-
var mods = annotsAsMods() | Param
3573+
def capParam(startOffset: Int, mods0: Modifiers): TypeDef = { // TODO grammar doc
3574+
val start = startOffset
3575+
var mods = mods0
35793576
if paramOwner.isClass then
35803577
mods |= PrivateLocal
35813578
ensureNoVariance() // TODO: in the future, we might want to support variances on capture params, ruled out for now
@@ -3594,9 +3591,9 @@ object Parsers {
35943591
}
35953592
}
35963593

3597-
def typeParam(): TypeDef = {
3598-
val start = in.offset
3599-
var mods = annotsAsMods() | Param
3594+
def typeParam(startOffset: Int, mods0: Modifiers): TypeDef = {
3595+
val start = startOffset
3596+
var mods = mods0
36003597
if paramOwner.isClass then
36013598
mods |= PrivateLocal
36023599
if isIdent(nme.raw.PLUS) && checkVarianceOK() then

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import caps.*
22

33
class IO
44

5-
def f[C^](io: IO^{C}) = ???
5+
def f[cap C](io: IO^{C}) = ???
66

77
def test =
8-
f[CapSet](???)
9-
f[CapSet^{}](???)
10-
f[CapSet^](???)
8+
f[{}](???)
9+
f[{}](???)
10+
f[{cap}](???)
1111
f[Nothing](???) // error
1212
f[String](???) // error

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[cap X, cap Y, cap 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/neg-custom-args/captures/capture-poly.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import caps.*
33
trait Foo extends Capability
44

55
trait CaptureSet:
6-
type C >: CapSet <: CapSet^
6+
cap type C
77

8-
def capturePoly[C^](a: Foo^{C}): Foo^{C} = a
8+
def capturePoly[cap C](a: Foo^{C}): Foo^{C} = a
99
def capturePoly2(c: CaptureSet)(a: Foo^{c.C}): Foo^{c.C} = a
1010

1111
def test =
1212
val x: Foo^ = ???
1313
val y: Foo^ = ???
1414

1515
object X extends CaptureSet:
16-
type C = CapSet^{x}
16+
cap type C = {x}
1717

1818
val z1: Foo^{X.C} = x
1919
val z2: Foo^{X.C} = y // error

tests/neg-custom-args/captures/capture-vars-subtyping.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import language.experimental.captureChecking
22
import caps.*
33

4-
def test[C^] =
4+
def test[cap C] =
55
val a: C = ???
66
val b: CapSet^{C} = a
77
val c: C = b
88
val d: CapSet^{C, c} = a
99

1010
// TODO: make "CapSet-ness" of type variables somehow contagious?
1111
// Then we don't have to spell out the bounds explicitly...
12-
def testTrans[C^, D >: CapSet <: C, E >: CapSet <: D, F >: C <: CapSet^] =
12+
def testTrans[cap C, cap D <: {C}, cap E <: {D}, cap F >: {C}] =
1313
val d1: D = ???
1414
val d2: CapSet^{D} = d1
1515
val d3: D = d2
@@ -35,14 +35,14 @@ trait A[+T]
3535

3636
trait B[-C]
3737

38-
def testCong[C^, D^] =
38+
def testCong[cap C, cap D] =
3939
val a: A[C] = ???
40-
val b: A[CapSet^{C}] = a
41-
val c: A[CapSet^{D}] = a // error
42-
val d: A[CapSet^{C,D}] = a
40+
val b: A[{C}] = a
41+
val c: A[{D}] = a // error
42+
val d: A[{C,D}] = a
4343
val e: A[C] = d // error
4444
val f: B[C] = ???
45-
val g: B[CapSet^{C}] = f
45+
val g: B[{C}] = f
4646
val h: B[C] = g
47-
val i: B[CapSet^{C,D}] = h // error
47+
val i: B[{C,D}] = h // error
4848
val j: B[C] = i

tests/neg-custom-args/captures/capture-vars-subtyping2.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ trait BoundsTest:
88

99
val b: Bar^ = ???
1010

11-
def testTransMixed[A^,
12-
B >: CapSet <: A,
13-
C >: CapSet <: CapSet^{B},
14-
D >: CapSet <: C,
15-
E >: CapSet <: CapSet^{D},
16-
F >: CapSet <: CapSet^{A,b},
17-
X >: CapSet <: CapSet^{F,D},
18-
Y >: CapSet^{F} <: CapSet^{F,A,b},
19-
Z >: CapSet^{b} <: CapSet^{b,Y}] =
11+
def testTransMixed[cap A,
12+
cap B <: {A},
13+
cap C <: {B},
14+
cap D <: {C},
15+
cap E <: {D},
16+
cap F <: {A,b},
17+
cap X <: {F,D},
18+
cap Y >: {F} <: {F,A,b},
19+
cap Z >: {b} <: {b,Y}] =
2020
val e: E = ???
2121
val e2: CapSet^{E} = e
2222
val ed: D = e
@@ -39,6 +39,6 @@ trait BoundsTest:
3939

4040
def callTransMixed =
4141
val x, y, z: Bar^ = ???
42-
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{b,x,y,z}]
43-
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y}, CapSet^{x,y}, CapSet^{x}, CapSet^{}, CapSet^{b,x}, CapSet^{b}, CapSet^{b,x}, CapSet^{b}]
44-
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y}, CapSet^{x,y}, CapSet^{x}, CapSet^{}, CapSet^{b,x}, CapSet^{b}, CapSet^{b,x}, CapSet^{b,x,y,z}] // error
42+
testTransMixed[{x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {b,x,y,z}]
43+
testTransMixed[{x,y,z}, {x,y}, {x,y}, {x}, {}, {b,x}, {b}, {b,x}, {b}]
44+
testTransMixed[{x,y,z}, {x,y}, {x,y}, {x}, {}, {b,x}, {b}, {b,x}, {b,x,y,z}] // error

tests/neg-custom-args/captures/cc-poly-1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Test:
66
class C extends Capability
77
class D
88

9-
def f[X^](x: D^{X}): D^{X} = x
9+
def f[cap X](x: D^{X}): D^{X} = x
1010

1111
def test(c1: C, c2: C) =
1212
f[Any](D()) // error

tests/neg-custom-args/captures/cc-poly-2.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-poly-2.scala:14:19 ------------------------------------
2-
14 | f[CapSet^{c1}](d) // error
3-
| ^
4-
| Found: (d : Test.D^)
5-
| Required: Test.D^{c1}
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-poly-2.scala:14:12 ------------------------------------
2+
14 | f[{c1}](d) // error
3+
| ^
4+
| Found: (d : Test.D^)
5+
| Required: Test.D^{c1}
66
|
77
| longer explanation available when compiling with `-explain`
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-poly-2.scala:16:20 ------------------------------------

tests/neg-custom-args/captures/cc-poly-2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ object Test:
66
class C extends Capability
77
class D
88

9-
def f[X^](x: D^{X}): D^{X} = x
9+
def f[cap X](x: D^{X}): D^{X} = x
1010

1111
def test(c1: C, c2: C) =
1212
val d: D^ = D()
1313
// f[Nothing](d) // already ruled out at typer
14-
f[CapSet^{c1}](d) // error
14+
f[{c1}](d) // error
1515
val x = f(d)
1616
val _: D^{c1} = x // error

tests/neg-custom-args/captures/cc-poly-source.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import caps.use
99

1010
class Listener
1111

12-
class Source[X^]:
12+
class Source[cap X]:
1313
private var listeners: Set[Listener^{X}] = Set.empty
1414
def register(x: Listener^{X}): Unit =
1515
listeners += x
1616

1717
def allListeners: Set[Listener^{X}] = listeners
1818

1919
def test1(lbl1: Label^, lbl2: Label^) =
20-
val src = Source[CapSet^{lbl1, lbl2}]
20+
val src = Source[{lbl1, lbl2}]
2121
def l1: Listener^{lbl1} = ???
2222
val l2: Listener^{lbl2} = ???
2323
src.register{l1}
@@ -31,7 +31,7 @@ import caps.use
3131
// we get an error here because we no longer allow contravariant cap
3232
// to subsume other capabilities. The problem can be solved by declaring
3333
// Label a SharedCapability, see cc-poly-source-capability.scala
34-
val src = Source[CapSet^{lbls*}]
34+
val src = Source[{lbls*}]
3535
for l <- listeners do
3636
src.register(l)
3737
val ls = src.allListeners

0 commit comments

Comments
 (0)