Skip to content

Commit d7b3f09

Browse files
committed
Update tests and restore parsing for infix ^ in types
1 parent a307ebd commit d7b3f09

File tree

5 files changed

+37
-30
lines changed

5 files changed

+37
-30
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ object Parsers {
16891689
if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil
16901690

16911691
/** InfixType ::= RefinedType {id [nl] RefinedType}
1692+
* | RefinedType `^`
16921693
*/
16931694
def infixType(): Tree = infixTypeRest(refinedType())
16941695

@@ -1708,7 +1709,13 @@ object Parsers {
17081709
refinedTypeRest(atSpan(startOffset(t)) {
17091710
RefinedTypeTree(rejectWildcardType(t), refinement(indentOK = true))
17101711
})
1711-
else if in.isIdent(nme.UPARROW) then
1712+
else if in.isIdent(nme.UPARROW)
1713+
&& (in.lookahead.token == LBRACE
1714+
|| !canStartInfixTypeTokens.contains(in.lookahead.token))
1715+
// Disambiguation: a `^` is treated as a postfix operator meaning `^{any}`
1716+
// if followed by `{` or newline, or any other token that cannot start
1717+
// an infix type. Otherwise it is treated as an infix operator.
1718+
then
17121719
val upArrowStart = in.offset
17131720
in.nextToken()
17141721
def cs =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import annotation.retainsByName
22
class CC
3-
type Cap = {*} CC
3+
type Cap = CC^
44

55
class I
66

7-
def test(cap1: Cap, cap2: Cap): I{ref cap1} =
7+
def test(cap1: Cap, cap2: Cap): I^{cap1} =
88
def f() = if cap1 == cap1 then I() else I()
9-
def h(x: ->{ref any} I) = x
9+
def h(x: ->{any} I) = x
1010
h(f()) // OK
1111
def hh(x: -> I @retainsByName(cap1)) = x
1212
h(f())

tests/pos-custom-args/captures/capt-test.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def map[A, B](f: A => B)(xs: LIST[A]): LIST[B] =
1919
xs.map(f)
2020

2121
class C
22-
type Cap = C{ref any}
22+
type Cap = C^
2323

2424
class Foo(x: Cap):
25-
this: Foo{ref x} =>
25+
this: Foo^{x} =>
2626

2727
def test(c: Cap, d: Cap) =
2828
def f(x: Cap): Unit = if c == x then ()
@@ -32,7 +32,7 @@ def test(c: Cap, d: Cap) =
3232
val zs =
3333
val z = g
3434
CONS(z, ys)
35-
val zsc: LIST[Cap ->{ref d, y} Unit] = zs
35+
val zsc: LIST[Cap ->{d, y} Unit] = zs
3636

3737
val a4 = zs.map(identity)
38-
val a4c: LIST[Cap ->{ref d, y} Unit] = a4
38+
val a4c: LIST[Cap ->{d, y} Unit] = a4
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import annotation.retains
22
class B
3-
type Cap = B{ref any}
3+
type Cap = B^
44
class C(val n: Cap):
5-
this: C{ref n} =>
6-
def foo(): B{ref n} = n
5+
this: C^{n} =>
6+
def foo(): B^{n} = n
77

88

99
def test(x: Cap, y: Cap, z: Cap) =
1010
val c0 = C(x)
11-
val c1: C{ref x}{val n: B{ref x}} = c0
11+
val c1: C{val n: B^{x}}^{x} = c0
1212
val d = c1.foo()
13-
d: B{ref x}
13+
d: B^{x}
1414

1515
val c2 = if ??? then C(x) else C(y)
1616
val c2a = identity(c2)
17-
val c3: C{ref x, y}{ val n: B{ref x, y} } = c2
17+
val c3: C{ val n: B^{x, y} }^{x, y} = c2
1818
val d1 = c3.foo()
19-
d1: B{ref x, y}
19+
d1: B^{x, y}
2020

2121
class Local:
2222

@@ -29,7 +29,7 @@ def test(x: Cap, y: Cap, z: Cap) =
2929
end Local
3030

3131
val l = Local()
32-
val l1: Local{ref x, y} = l
32+
val l1: Local^{x, y} = l
3333
val l2 = Local(x)
34-
val l3: Local{ref x, y, z} = l2
34+
val l3: Local^{x, y, z} = l2
3535

tests/run-custom-args/captures/colltest5/Test_2.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
import colltest5.strawman.collections.*
66
import CollectionStrawMan5.*
77

8-
def seqOps(xs: Seq[Int]) = { // try with Seq[Int]{ref any}
8+
def seqOps(xs: Seq[Int]) = { // try with Seq[Int]^{any}
99
val strPlusInt: (String, Int) => String = _ + _
1010
val intPlusStr: (Int, String) => String = _ + _
1111
val isEven: Int => Boolean = _ % 2 == 0
@@ -61,7 +61,7 @@ object Test {
6161
println(xs16)
6262
}
6363

64-
def viewOps(xs: View[Int]{ref any}) = {
64+
def viewOps(xs: View[Int]^{any}) = {
6565
val strPlusInt: (String, Int) => String = _ + _
6666
val intPlusStr: (Int, String) => String = _ + _
6767
val isEven: Int => Boolean = _ % 2 == 0
@@ -78,27 +78,27 @@ object Test {
7878
val x5 = xs.to(List)
7979
val y5: List[Int] = x5
8080
val (xs6, xs7) = xs.partition(isEven)
81-
val ys6: View[Int]{ref xs6, isEven} = xs6
82-
val ys7: View[Int]{ref xs7, isEven} = xs7
81+
val ys6: View[Int]^{xs6, isEven} = xs6
82+
val ys7: View[Int]^{xs7, isEven} = xs7
8383
val (xs6a, xs7a) = xs.partition(_ % 2 == 0)
84-
val ys6a: View[Int]{ref xs6} = xs6
85-
val ys7a: View[Int]{ref xs7} = xs7
84+
val ys6a: View[Int]^{xs6} = xs6
85+
val ys7a: View[Int]^{xs7} = xs7
8686
val xs8 = xs.drop(2)
87-
val ys8: View[Int]{ref xs8} = xs8
87+
val ys8: View[Int]^{xs8} = xs8
8888
val xs9 = xs.map(isNonNeg)
89-
val ys9: View[Boolean]{ref xs9} = xs9
89+
val ys9: View[Boolean]^{xs9} = xs9
9090
val xs10 = xs.flatMap(flips)
91-
val ys10: View[Int]{ref xs10} = xs10
91+
val ys10: View[Int]^{xs10} = xs10
9292
val xs11 = xs ++ xs
93-
val ys11: View[Int]{ref xs11} = xs11
93+
val ys11: View[Int]^{xs11} = xs11
9494
val xs12 = xs ++ Nil
95-
val ys12: View[Int]{ref xs12} = xs12
95+
val ys12: View[Int]^{xs12} = xs12
9696
val xs13 = Nil ++ xs
9797
val ys13: List[Int] = xs13
9898
val xs14 = xs ++ Cons("a", Nil)
99-
val ys14: View[Any]{ref xs14} = xs14
99+
val ys14: View[Any]^{xs14} = xs14
100100
val xs15 = xs.zip(xs9)
101-
val ys15: View[(Int, Boolean)]{ref xs15} = xs15
101+
val ys15: View[(Int, Boolean)]^{xs15} = xs15
102102
println("-------")
103103
println(x1)
104104
println(x2)

0 commit comments

Comments
 (0)