diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 329135a02b32..3c3142906015 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -389,6 +389,8 @@ class Namer { typer: Typer => val name = checkNoConflict(tree.name, flags.is(Private), tree.span) tree match case tree: ValOrDefDef => + if tree.isInstanceOf[ValDef] && !flags.is(Param) && name.endsWith("_=") then + ctx.error("Names of vals or vars may not end in `_=`", tree.namePos) if tree.unforcedRhs == EmptyTree && !flags.isOneOf(TermParamOrAccessor) && !tree.name.isConstructorName diff --git a/tests/neg/i9023.scala b/tests/neg/i9023.scala new file mode 100644 index 000000000000..d27cdcbf1f8b --- /dev/null +++ b/tests/neg/i9023.scala @@ -0,0 +1,19 @@ +class C { + var __= : Int = 42 // error + var x_= : Int = 42 // error +} + +class D { + val __= : Int = 42 // error + val x_= : Int = 42 // error +} + +class E { + lazy val __= : Int = 42 // error + lazy val x_= : Int = 42 // error +} + +class F { + def __= : Int = 42 + def x_= : Int = 42 +}