Skip to content

Commit 3e443b6

Browse files
committed
Make capture parameters and members bounded by CapSet by default
1 parent 5d1d274 commit 3e443b6

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,14 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
527527
def makeCapsOf(tp: RefTree)(using Context): Tree =
528528
TypeApply(Select(scalaDot(nme.caps), nme.capsOf), tp :: Nil)
529529

530-
def makeCapsBound()(using Context): Tree =
531-
makeRetaining(
530+
// `type C^` and `[C^]` becomes:
531+
// `type C >: CapSet <: CapSet^{cap}` and `[C >: CapSet <: CapSet^{cap}]`
532+
def makeCapsBound()(using Context): TypeBoundsTree =
533+
TypeBoundsTree(
532534
Select(scalaDot(nme.caps), tpnme.CapSet),
533-
Nil, tpnme.retainsCap)
535+
makeRetaining(
536+
Select(scalaDot(nme.caps), tpnme.CapSet),
537+
Nil, tpnme.retainsCap))
534538

535539
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(using Context): DefDef =
536540
DefDef(nme.CONSTRUCTOR, joinParams(tparams, vparamss), TypeTree(), rhs)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ object Parsers {
22402240
atSpan(in.offset):
22412241
if in.isIdent(nme.UPARROW) && Feature.ccEnabled then
22422242
in.nextToken()
2243-
TypeBoundsTree(EmptyTree, makeCapsBound())
2243+
makeCapsBound()
22442244
else
22452245
TypeBoundsTree(bound(SUPERTYPE), bound(SUBTYPE))
22462246

@@ -4057,8 +4057,11 @@ object Parsers {
40574057
|| sourceVersion.isAtLeast(`3.6`) && in.isColon =>
40584058
makeTypeDef(typeAndCtxBounds(tname))
40594059
case _ =>
4060-
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
4061-
return EmptyTree // return to avoid setting the span to EmptyTree
4060+
if in.isIdent(nme.UPARROW) && Feature.ccEnabled then
4061+
makeTypeDef(typeAndCtxBounds(tname))
4062+
else
4063+
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
4064+
return EmptyTree // return to avoid setting the span to EmptyTree
40624065
}
40634066
}
40644067
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import caps.*
2+
3+
class IO
4+
5+
def f[C^](io: IO^{C^}) = ???
6+
7+
def test =
8+
f[CapSet](???)
9+
f[CapSet^{}](???)
10+
f[CapSet^](???)
11+
f[Nothing](???) // error
12+
f[String](???) // error
13+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import caps.*
2+
3+
trait Abstract[X^]:
4+
type C >: X <: CapSet^
5+
def boom(): Unit^{C^}
6+
7+
class Concrete extends Abstract[CapSet^{}]:
8+
type C = CapSet^{}
9+
def boom() = ()
10+
11+
class Concrete2 extends Abstract[CapSet^{}]:
12+
type C = CapSet^{} & CapSet^{}
13+
def boom() = ()
14+
15+
class Concrete3 extends Abstract[CapSet^{}]:
16+
type C = CapSet^{} | CapSet^{}
17+
def boom() = ()
18+
19+
class Concrete4 extends Abstract[CapSet^{}]:
20+
type C = Nothing // error
21+
def boom() = ()

0 commit comments

Comments
 (0)