Skip to content

Commit fc69c1d

Browse files
committed
Add test
1 parent bec1174 commit fc69c1d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,9 @@ trait Checking {
740740
!infixOKSinceFollowedBy(tree.right) &&
741741
ctx.settings.strict.value =>
742742
ctx.deprecationWarning(
743-
i"""alphanumeric method $name is not declared @infix; should not be used as infix operator.
744-
|The operation can be rewritten automatically to `$name` under -deprecation -rewrite""",
743+
i"""Alphanumeric method $name is not declared @infix; it should not be used as infix operator.
744+
|The operation can be rewritten automatically to `$name` under -deprecation -rewrite.
745+
|Or rewrite to method syntax .$name(...) manually.""",
745746
tree.op.sourcePos)
746747
if (ctx.settings.deprecation.value) {
747748
patch(Span(tree.op.span.start, tree.op.span.start), "`")

tests/neg-custom-args/infix.scala

Lines changed: 15 additions & 0 deletions
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)