Skip to content

Commit 398cc18

Browse files
committed
Fix #9023: Check that names of vals and vars do not end with _=
1 parent 427aae6 commit 398cc18

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,12 @@ trait Checking {
882882
}
883883
}
884884

885+
/** Checks that the name is allowed */
886+
def checkValidName(vdef: ValDef)(using Context): Unit = {
887+
if vdef.name.endsWith("_=") && vdef.symbol.owner.isClass then
888+
ctx.error("Names of vals or vars may not end in `_=`", vdef.namePos)
889+
}
890+
885891
/** Check that `tree` can be right hand-side or argument to `inline` value or parameter. */
886892
def checkInlineConformant(tpt: Tree, tree: Tree, sym: Symbol)(using Context): Unit = {
887893
if sym.is(Inline, butNot = DeferredOrTermParamOrAccessor) && !ctx.erasedTypes && !Inliner.inInlineMethod then

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,7 @@ class Typer extends Namer
18021802
}
18031803
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
18041804
checkSignatureRepeatedParam(sym)
1805+
checkValidName(vdef1)
18051806
checkInlineConformant(tpt1, rhs1, sym)
18061807
patchFinalVals(vdef1)
18071808
vdef1.setDefTree

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)