From 4328f3feb8f3bf70c78ce1cd07ef6d71a92a9506 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 22 May 2020 13:26:19 +0200 Subject: [PATCH] Fix #9023: Check that names of vals and vars do not end with `_=` --- .../src/dotty/tools/dotc/typer/Namer.scala | 2 ++ tests/neg/i9023.scala | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/neg/i9023.scala 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 +}