From aa50558f08ff128f14ce2d759a108d2f76f21603 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 25 Sep 2019 17:33:19 +0200 Subject: [PATCH] Fix #7296: Don't flag setter names as operator names --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 11 ++++++----- compiler/test/dotty/tools/dotc/CompilationTests.scala | 3 ++- tests/pos-special/i7296.scala | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 tests/pos-special/i7296.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index d50f662d7652..9d63c2a0da98 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -278,11 +278,12 @@ object Checking { def checkValidOperator(sym: Symbol)(implicit ctx: Context): Unit = sym.name.toTermName match { case name: SimpleName - if name.exists(isOperatorPart) && - !sym.getAnnotation(defn.AlphaAnnot).isDefined && - !sym.is(Synthetic) && - !name.isConstructorName && - ctx.settings.strict.value => + if name.exists(isOperatorPart) + && !name.isSetterName + && !name.isConstructorName + && !sym.getAnnotation(defn.AlphaAnnot).isDefined + && !sym.is(Synthetic) + && ctx.settings.strict.value => ctx.deprecationWarning( i"$sym has an operator name; it should come with an @alpha annotation", sym.sourcePos) case _ => diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index ecf290c842c1..32087a21ba85 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -57,7 +57,8 @@ class CompilationTests extends ParallelTesting { defaultOptions.and("-nowarn", "-Xfatal-warnings") ), compileFile("tests/pos-special/typeclass-scaling.scala", defaultOptions.and("-Xmax-inlines", "40")), - compileFile("tests/pos-special/indent-colons.scala", defaultOptions.and("-Yindent-colons")) + compileFile("tests/pos-special/indent-colons.scala", defaultOptions.and("-Yindent-colons")), + compileFile("tests/pos-special/i7296.scala", defaultOptions.and("-strict", "-deprecation", "-Xfatal-warnings")) ).checkCompile() } diff --git a/tests/pos-special/i7296.scala b/tests/pos-special/i7296.scala new file mode 100644 index 000000000000..aa21e75ff741 --- /dev/null +++ b/tests/pos-special/i7296.scala @@ -0,0 +1,2 @@ +class Foo + private var blah: Double = 0L \ No newline at end of file