Skip to content

Commit 4a40cd7

Browse files
committed
Address review comments
1 parent 5004928 commit 4a40cd7

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,6 @@ object Parsers {
15931593
}
15941594

15951595
/** CaptureRef ::= { SimpleRef `.` } SimpleRef [`*`] [`.` `rd`] -- under captureChecking
1596-
* | [ { SimpleRef `.` } SimpleRef `.` ] id
15971596
*/
15981597
def captureRef(): Tree =
15991598

@@ -2183,7 +2182,7 @@ object Parsers {
21832182
* NameAndType ::= id ‘:’ Type
21842183
*/
21852184
def argTypes(namedOK: Boolean, wildOK: Boolean, tupleOK: Boolean): List[Tree] =
2186-
inline def wildCardCheck(inline gen: Tree): Tree =
2185+
def wildCardCheck(gen: Tree): Tree =
21872186
val t = gen
21882187
if wildOK then t else rejectWildcardType(t)
21892188

@@ -2210,7 +2209,7 @@ object Parsers {
22102209
if namedOK && (isIdent && in.lookahead.token == EQUALS) then
22112210
commaSeparated(() => namedTypeArg())
22122211
else if tupleOK && isIdent && in.lookahead.isColon && sourceVersion.enablesNamedTuples then
2213-
commaSeparated(() => nameAndType()) // TODO: can capture-set variables occur here?
2212+
commaSeparated(() => nameAndType())
22142213
else
22152214
commaSeparated(() => typeArg())
22162215
end argTypes
@@ -2279,9 +2278,9 @@ object Parsers {
22792278
TypeBoundsTree(bound(SUPERTYPE), bound(SUBTYPE))
22802279

22812280
private def bound(tok: Int): Tree =
2282-
if (in.token == tok) then
2281+
if in.token == tok then
22832282
in.nextToken()
2284-
if Feature.ccEnabled && (in.token == LBRACE && !isDclIntroNext) then
2283+
if Feature.ccEnabled && in.token == LBRACE && !isDclIntroNext then
22852284
capsBound(captureSet(), isLowerBound = tok == SUPERTYPE)
22862285
else toplevelTyp()
22872286
else EmptyTree
@@ -2290,7 +2289,7 @@ object Parsers {
22902289
if isLowerBound && refs.isEmpty then // lower bounds with empty capture sets become a pure CapSet
22912290
Select(scalaDot(nme.caps), tpnme.CapSet)
22922291
else
2293-
makeRetaining(Select(scalaDot(nme.caps), tpnme.CapSet), refs, tpnme.retains)
2292+
concreteCapsType(refs)
22942293

22952294
/** TypeAndCtxBounds ::= TypeBounds [`:` ContextBounds]
22962295
*/

docs/_docs/internals/syntax.md

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ NamesAndTypes ::= NameAndType {‘,’ NameAndType}
242242
NameAndType ::= id ':' Type
243243
CaptureSet ::= ‘{’ CaptureRef {‘,’ CaptureRef} ‘}’ -- under captureChecking
244244
CaptureRef ::= { SimpleRef ‘.’ } SimpleRef [‘*’] [‘.’ ‘rd’] -- under captureChecking
245-
| [ { SimpleRef ‘.’ } SimpleRef ‘.’ ] id -- under captureChecking
246245
```
247246

248247
### Expressions

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import language.experimental.captureChecking
12
import caps.*
23

34
class IO
@@ -6,6 +7,7 @@ case class File(io: IO^)
67

78
def test(io1: IO^, io2: IO^) =
89
def f[C^ >: {io1}](file: File^{C}) = ???
10+
def g[C >: {io1}](file: File^{C}) = ???
911
val f1: File^{io1} = ???
1012
val f2: File^{io2} = ???
1113
val f3: File^{io1, io2} = ???
@@ -15,4 +17,11 @@ def test(io1: IO^, io2: IO^) =
1517
f[{io2}](f2) // error
1618
f[{io1, io2}](f1)
1719
f[{io1, io2}](f2)
18-
f[{io1, io2}](f3)
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import language.experimental.captureChecking
2+
import caps.*
3+
4+
trait Abstract[X^]:
5+
type C >: {X}
6+
// Don't test the return type using Unit, because it is a pure type.
7+
def boom(): AnyRef^{C}
8+
9+
class Concrete extends Abstract[{}]:
10+
type C^ = {}
11+
// TODO: Why do we get error without the return type here?
12+
def boom(): AnyRef = new Object
13+
14+
class Concrete2 extends Abstract[{}]:
15+
type C^ = {}
16+
def boom(): AnyRef^ = new Object // error
17+
18+
class Concrete3 extends Abstract[{}]:
19+
def boom(): AnyRef = new Object
20+
21+
class Concrete4(a: AnyRef^) extends Abstract[{a}]:
22+
type C^ = {} // error
23+
def boom(): AnyRef^{a} = a // error
24+
25+
class Concrete5(a: AnyRef^, b: AnyRef^) extends Abstract[{a}]:
26+
type C^ = {a}
27+
def boom(): AnyRef^{b} = b // error
28+
29+
class Concrete6(a: AnyRef^, b: AnyRef^) extends Abstract[{a}]:
30+
def boom(): AnyRef^{b} = b // error

0 commit comments

Comments
 (0)