Skip to content

Commit b829c69

Browse files
committed
Syntax change: allow capture sets in infix types
1 parent 02489af commit b829c69

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -1551,11 +1551,7 @@ object Parsers {
15511551
else { accept(TLARROW); typ() }
15521552
}
15531553
else if in.token == LBRACE && followingIsCaptureSet() then
1554-
val refs = inBraces {
1555-
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1556-
}
1557-
val t = typ()
1558-
CapturingTypeTree(refs, t)
1554+
CapturingTypeTree(captureSet(), typ())
15591555
else if (in.token == INDENT) enclosed(INDENT, typ())
15601556
else infixType()
15611557

@@ -1941,8 +1937,14 @@ object Parsers {
19411937
def typeDependingOn(location: Location): Tree =
19421938
if location.inParens then typ()
19431939
else if location.inPattern then rejectWildcardType(refinedType())
1940+
else if in.token == LBRACE && followingIsCaptureSet() then
1941+
CapturingTypeTree(captureSet(), infixType())
19441942
else infixType()
19451943

1944+
def captureSet(): List[Tree] = inBraces {
1945+
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1946+
}
1947+
19461948
/* ----------- EXPRESSIONS ------------------------------------------------ */
19471949

19481950
/** Does the current conditional expression continue after
@@ -2012,7 +2014,7 @@ object Parsers {
20122014
* | ‘inline’ InfixExpr MatchClause
20132015
* Bindings ::= `(' [Binding {`,' Binding}] `)'
20142016
* Binding ::= (id | `_') [`:' Type]
2015-
* Ascription ::= `:' InfixType
2017+
* Ascription ::= `:' [CaptureSet] InfixType
20162018
* | `:' Annotation {Annotation}
20172019
* | `:' `_' `*'
20182020
* Catches ::= ‘catch’ (Expr | ExprCaseClause)
@@ -4035,6 +4037,8 @@ object Parsers {
40354037
* |
40364038
* EnumStat ::= TemplateStat
40374039
* | Annotations Modifiers EnumCase
4040+
* SelfType ::= id [‘:’ [CaptureSet] InfixType] ‘=>’
4041+
* | ‘this’ ‘:’ [CaptureSet] InfixType ‘=>’
40384042
*/
40394043
def templateStatSeq(): (ValDef, List[Tree]) = checkNoEscapingPlaceholders {
40404044
val stats = new ListBuffer[Tree]

tests/disabled/pos/lazylist.scala

+1-1
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

+2-2
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

+1-1
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

+4-4
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

+2-2
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)