Skip to content

Commit eb75c72

Browse files
committed
Syntax change: allow capture sets in infix types
1 parent fa96111 commit eb75c72

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
@@ -1490,11 +1490,7 @@ object Parsers {
14901490
else { accept(TLARROW); typ() }
14911491
}
14921492
else if in.token == LBRACE && followingIsCaptureSet() then
1493-
val refs = inBraces {
1494-
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1495-
}
1496-
val t = typ()
1497-
CapturingTypeTree(refs, t)
1493+
CapturingTypeTree(captureSet(), typ())
14981494
else if (in.token == INDENT) enclosed(INDENT, typ())
14991495
else infixType()
15001496

@@ -1887,8 +1883,14 @@ object Parsers {
18871883
def typeDependingOn(location: Location): Tree =
18881884
if location.inParens then typ()
18891885
else if location.inPattern then rejectWildcardType(refinedType())
1886+
else if in.token == LBRACE && followingIsCaptureSet() then
1887+
CapturingTypeTree(captureSet(), infixType())
18901888
else infixType()
18911889

1890+
def captureSet(): List[Tree] = inBraces {
1891+
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1892+
}
1893+
18921894
/* ----------- EXPRESSIONS ------------------------------------------------ */
18931895

18941896
/** Does the current conditional expression continue after
@@ -1958,7 +1960,7 @@ object Parsers {
19581960
* | ‘inline’ InfixExpr MatchClause
19591961
* Bindings ::= `(' [Binding {`,' Binding}] `)'
19601962
* Binding ::= (id | `_') [`:' Type]
1961-
* Ascription ::= `:' InfixType
1963+
* Ascription ::= `:' [CaptureSet] InfixType
19621964
* | `:' Annotation {Annotation}
19631965
* | `:' `_' `*'
19641966
* Catches ::= ‘catch’ (Expr | ExprCaseClause)
@@ -3944,7 +3946,7 @@ object Parsers {
39443946
stats.toList
39453947
}
39463948

3947-
/** TemplateStatSeq ::= [id [`:' Type] `=>'] TemplateStat {semi TemplateStat}
3949+
/** TemplateStatSeq ::= [SelfType] TemplateStat {semi TemplateStat}
39483950
* TemplateStat ::= Import
39493951
* | Export
39503952
* | Annotations Modifiers Def
@@ -3954,6 +3956,8 @@ object Parsers {
39543956
* |
39553957
* EnumStat ::= TemplateStat
39563958
* | Annotations Modifiers EnumCase
3959+
* SelfType ::= id [‘:’ [CaptureSet] InfixType] ‘=>’
3960+
* | ‘this’ ‘:’ [CaptureSet] InfixType ‘=>’
39573961
*/
39583962
def templateStatSeq(): (ValDef, List[Tree]) = checkNoEscapingPlaceholders {
39593963
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)