File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -1389,7 +1389,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13891389 def lhs1 = adapt(lhsCore, LhsProto , locked)
13901390
13911391 def reassignmentToVal =
1392- report.error(ReassignmentToVal (lhsCore.symbol.name), tree.srcPos)
1392+ val lhsName = lhsCore match {
1393+ case nameTree : NameTree => nameTree.name
1394+ case _ => lhsCore.symbol.name
1395+ }
1396+ report.error(ReassignmentToVal (lhsName), tree.srcPos)
13931397 cpy.Assign (tree)(lhsCore, typed(tree.rhs, lhs1.tpe.widen)).withType(defn.UnitType )
13941398
13951399 def canAssign (sym : Symbol ) =
Original file line number Diff line number Diff line change 1+ -- [E052] Type Error: tests/neg/i22671.scala:6:6 -----------------------------------------------------------------------
2+ 6 | X.x = 27 // error
3+ | ^^^^^^^^
4+ | Reassignment to val x
5+ |
6+ | longer explanation available when compiling with `-explain`
7+ -- [E052] Type Error: tests/neg/i22671.scala:10:4 ----------------------------------------------------------------------
8+ 10 | x = 27 // error
9+ | ^^^^^^
10+ | Reassignment to val x
11+ |
12+ | longer explanation available when compiling with `-explain`
13+ -- [E052] Type Error: tests/neg/i22671.scala:14:4 ----------------------------------------------------------------------
14+ 14 | x = 27 // error
15+ | ^^^^^^
16+ | Reassignment to val x
17+ |
18+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change 1+ object X :
2+ def x : Int = 42
3+ def x (y : Int ): Int = x + y
4+
5+ def test1 =
6+ X .x = 27 // error
7+
8+ def test2 =
9+ import X .x
10+ x = 27 // error
11+
12+ def test3 =
13+ val x = 42
14+ x = 27 // error
You can’t perform that action at this time.
0 commit comments