Skip to content

Fix #9023: Check that names of vals and vars do not end with _= #9025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/neg/i9023.scala
Original file line number Diff line number Diff line change
@@ -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
}