Skip to content

Commit 0a62671

Browse files
authored
Merge pull request #9025 from dotty-staging/fix-#9023
Fix #9023: Check that names of vals and vars do not end with `_=`
2 parents 1363843 + 4328f3f commit 0a62671

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ class Namer { typer: Typer =>
389389
val name = checkNoConflict(tree.name, flags.is(Private), tree.span)
390390
tree match
391391
case tree: ValOrDefDef =>
392+
if tree.isInstanceOf[ValDef] && !flags.is(Param) && name.endsWith("_=") then
393+
ctx.error("Names of vals or vars may not end in `_=`", tree.namePos)
392394
if tree.unforcedRhs == EmptyTree
393395
&& !flags.isOneOf(TermParamOrAccessor)
394396
&& !tree.name.isConstructorName

tests/neg/i9023.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class C {
2+
var __= : Int = 42 // error
3+
var x_= : Int = 42 // error
4+
}
5+
6+
class D {
7+
val __= : Int = 42 // error
8+
val x_= : Int = 42 // error
9+
}
10+
11+
class E {
12+
lazy val __= : Int = 42 // error
13+
lazy val x_= : Int = 42 // error
14+
}
15+
16+
class F {
17+
def __= : Int = 42
18+
def x_= : Int = 42
19+
}

0 commit comments

Comments
 (0)