Skip to content

Commit 68ebca8

Browse files
committed
Add test
1 parent 2e7b4ad commit 68ebca8

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,9 @@ trait Checking {
687687
!infixOKSinceFollowedBy(tree.right) &&
688688
ctx.settings.strict.value =>
689689
ctx.deprecationWarning(
690-
i"""alphanumeric method $name is not declared @infix; should not be used as infix operator.
691-
|The operation can be rewritten automatically to `$name` under -deprecation -rewrite""",
690+
i"""Alphanumeric method $name is not declared @infix; it should not be used as infix operator.
691+
|The operation can be rewritten automatically to `$name` under -deprecation -rewrite.
692+
|Or rewrite to method syntax .$name(...) manually.""",
692693
tree.op.sourcePos)
693694
if (ctx.settings.deprecation.value) {
694695
patch(Span(tree.op.span.start, tree.op.span.start), "`")

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

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class CompilationTests extends ParallelTesting {
156156
compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) +
157157
compileFile("tests/neg-custom-args/i1050.scala", defaultOptions.and("-strict")) +
158158
compileFile("tests/neg-custom-args/nullless.scala", defaultOptions.and("-strict")) +
159+
compileFile("tests/neg-custom-args/infix.scala", defaultOptions.and("-strict", "-Xfatal-warnings", "-deprecation")) +
159160
compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")) +
160161
compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")) +
161162
compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) +

tests/neg-custom-args/infix.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}
7+
8+
val c = C()
9+
def test() = {
10+
c op 2
11+
c.meth(2)
12+
13+
c.op(2)
14+
c meth 2 // error: should not be used as infix operator
15+
}

0 commit comments

Comments
 (0)