Skip to content

Commit ba04554

Browse files
committed
Fix test
1 parent c0daac1 commit ba04554

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class CompilationTests extends ParallelTesting {
177177
"tests/neg-custom-args/toplevel-samesource/S.scala",
178178
"tests/neg-custom-args/toplevel-samesource/nested/S.scala"),
179179
defaultOptions),
180-
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes)
180+
compileFile("tests/neg-custom-args/i6300.scala", allowDeepSubtypes),
181+
compileFile("tests/neg-custom-args/infix.scala", defaultOptions.and("-strict", "-deprecation", "-Xfatal-warnings"))
181182
).checkExpectedErrors()
182183
}
183184

tests/neg-custom-args/infix.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def test() = {
4949
val Pair(_, _) = p
5050
val _ Pair _ = p // error
5151
val _ `Pair` _ = p // OK
52-
val _ PP _ = p // OK
52+
val (_ PP _): @unchecked = p // OK
5353

5454
val q = Q(1, 2)
5555
val Q(_, _) = q
56-
val _ Q _ = p // OK
56+
val _ Q _ = q // OK
5757

5858

5959
}

tests/neg-strict/infix.scala

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Compile with -strict -Xfatal-warnings -deprecation
2+
import scala.annotation.infix
3+
class C {
4+
@infix def op(x: Int): Int = ???
5+
def meth(x: Int): Int = ???
6+
def matching(x: Int => Int) = ???
7+
def +(x: Int): Int = ???
8+
}
9+
10+
val c = C()
11+
def test() = {
12+
c op 2
13+
c.meth(2)
14+
15+
c.op(2)
16+
c meth 2 // error: should not be used as infix operator
17+
c `meth` 2 // OK, sincd `meth` is backquoted
18+
c + 3 // OK, since `+` is symbolic
19+
1 to 2 // OK, since `to` is defined by Scala-2
20+
c meth { // OK, since `meth` is followed by `{...}`
21+
3
22+
}
23+
c matching { // OK, since `meth` is followed by `{...}`
24+
case x => x
25+
}
26+
27+
@infix class Or[X, Y]
28+
class AndC[X, Y]
29+
@infix type And[X, Y] = AndC[X, Y]
30+
@infix type &&[X, Y] = AndC[X, Y]
31+
32+
class Map[X, Y]
33+
34+
val x1: Int Map String = ??? // error
35+
val x2: Int Or String = ??? // OK since Or is declared `@infix`
36+
val x3: Int AndC String = ??? // error
37+
val x4: Int `AndC` String = ??? // OK
38+
val x5: Int And String = ??? // OK
39+
val x6: Int && String = ???
40+
41+
case class Pair[T](x: T, y: T)
42+
@infix case class Q[T](x: T, y: T)
43+
44+
object PP {
45+
@infix def unapply[T](x: Pair[T]): Option[(T, T)] = Some((x.x, x.y))
46+
}
47+
48+
val p = Pair(1, 2)
49+
val Pair(_, _) = p
50+
val _ Pair _ = p // error
51+
val _ `Pair` _ = p // OK
52+
val (_ PP _): @unchecked = p // OK
53+
54+
val q = Q(1, 2)
55+
val Q(_, _) = q
56+
val _ Q _ = q // OK
57+
58+
59+
}

0 commit comments

Comments
 (0)