Skip to content

Commit b676034

Browse files
committed
Syntax change: allow capture sets in infix types
1 parent b90dd6b commit b676034

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,11 +1492,7 @@ object Parsers {
14921492
else { accept(TLARROW); typ() }
14931493
}
14941494
else if in.token == LBRACE && followingIsCaptureSet() then
1495-
val refs = inBraces {
1496-
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1497-
}
1498-
val t = typ()
1499-
CapturingTypeTree(refs, t)
1495+
CapturingTypeTree(captureSet(), typ())
15001496
else if (in.token == INDENT) enclosed(INDENT, typ())
15011497
else infixType()
15021498

@@ -1879,8 +1875,14 @@ object Parsers {
18791875
def typeDependingOn(location: Location): Tree =
18801876
if location.inParens then typ()
18811877
else if location.inPattern then rejectWildcardType(refinedType())
1878+
else if in.token == LBRACE && followingIsCaptureSet() then
1879+
CapturingTypeTree(captureSet(), infixType())
18821880
else infixType()
18831881

1882+
def captureSet(): List[Tree] = inBraces {
1883+
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1884+
}
1885+
18841886
/* ----------- EXPRESSIONS ------------------------------------------------ */
18851887

18861888
/** Does the current conditional expression continue after
@@ -1950,7 +1952,7 @@ object Parsers {
19501952
* | ‘inline’ InfixExpr MatchClause
19511953
* Bindings ::= `(' [Binding {`,' Binding}] `)'
19521954
* Binding ::= (id | `_') [`:' Type]
1953-
* Ascription ::= `:' InfixType
1955+
* Ascription ::= `:' [CaptureSet] InfixType
19541956
* | `:' Annotation {Annotation}
19551957
* | `:' `_' `*'
19561958
* Catches ::= ‘catch’ (Expr | ExprCaseClause)
@@ -3910,7 +3912,7 @@ object Parsers {
39103912
stats.toList
39113913
}
39123914

3913-
/** TemplateStatSeq ::= [id [`:' Type] `=>'] TemplateStat {semi TemplateStat}
3915+
/** TemplateStatSeq ::= [SelfType] TemplateStat {semi TemplateStat}
39143916
* TemplateStat ::= Import
39153917
* | Export
39163918
* | Annotations Modifiers Def
@@ -3920,6 +3922,8 @@ object Parsers {
39203922
* |
39213923
* EnumStat ::= TemplateStat
39223924
* | Annotations Modifiers EnumCase
3925+
* SelfType ::= id [‘:’ [CaptureSet] InfixType] ‘=>’
3926+
* | ‘this’ ‘:’ [CaptureSet] InfixType ‘=>’
39233927
*/
39243928
def templateStatSeq(): (ValDef, List[Tree]) = checkNoEscapingPlaceholders {
39253929
var self: ValDef = EmptyValDef

tests/disabled/pos/lazylist.scala

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

33
abstract class LazyList[+T]:
4-
this: ({*} LazyList[T]) =>
4+
this: {*} LazyList[T] =>
55

66
def isEmpty: Boolean
77
def head: T

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
class B
22
type Cap = {*} B
33
class C(val n: Cap):
4-
this: ({n} C) =>
4+
this: {n} C =>
55
def foo(): {n} B = n
66

77

88
def test(x: Cap, y: Cap, z: Cap) =
99
val c0 = C(x)
1010
val c1: {x} C {val n: {x} B} = c0
1111
val d = c1.foo()
12-
d: ({x} B)
12+
d: {x} B
1313

1414
val c2 = if ??? then C(x) else C(y)
1515
val c2a = identity(c2)

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

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

33
abstract class Iterator[T]:
4-
thisIterator: ({*} Iterator[T]) =>
4+
thisIterator: {*} Iterator[T] =>
55

66
def hasNext: Boolean
77
def next: T

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class CC
22
type Cap = {*} CC
33

44
trait LazyList[+A]:
5-
this: ({*} LazyList[A]) =>
5+
this: {*} LazyList[A] =>
66

77
def isEmpty: Boolean
88
def head: A
@@ -16,12 +16,12 @@ object LazyNil extends LazyList[Nothing]:
1616
extension [A](xs: {*} LazyList[A])
1717
def map[B](f: A => B): {xs, f} LazyList[B] =
1818
final class Mapped extends LazyList[B]:
19-
this: ({xs, f} Mapped) =>
19+
this: {xs, f} Mapped =>
2020

2121
def isEmpty = false
2222
def head: B = f(xs.head)
2323
def tail: {this} LazyList[B] = xs.tail.map(f) // OK
24-
def concat(other: {f} LazyList[A]): {this, f} LazyList[A] = ??? : ({xs, f} LazyList[A]) // OK
24+
def concat(other: {f} LazyList[A]): {this, f} LazyList[A] = ??? : {xs, f} LazyList[A] // OK
2525
if xs.isEmpty then LazyNil
2626
else new Mapped
2727

@@ -31,7 +31,7 @@ def test(cap1: Cap, cap2: Cap) =
3131

3232
val xs =
3333
class Initial extends LazyList[String]:
34-
this: ({cap1} Initial) =>
34+
this: {cap1} Initial =>
3535

3636
def isEmpty = false
3737
def head = f("")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class CC
22
type Cap = {*} CC
33

44
trait LazyList[+A]:
5-
this: ({*} LazyList[A]) =>
5+
this: {*} LazyList[A] =>
66

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

1616
final class LazyCons[+T](val x: T, val xs: Int => {*} LazyList[T]) extends LazyList[T]:
17-
this: ({*} LazyList[T]) =>
17+
this: {*} LazyList[T] =>
1818

1919
def isEmpty = false
2020
def head = x

0 commit comments

Comments
 (0)