diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9e76d57c763c..646295451c95 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1000,8 +1000,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer def lhs1 = adapt(lhsCore, AssignProto, locked) def reassignmentToVal = - errorTree(cpy.Assign(tree)(lhsCore, typed(tree.rhs, lhs1.tpe.widen)), - ReassignmentToVal(lhsCore.symbol.name)) + report.error(ReassignmentToVal(lhsCore.symbol.name), tree.srcPos) + cpy.Assign(tree)(lhsCore, typed(tree.rhs, lhs1.tpe.widen)).withType(defn.UnitType) def canAssign(sym: Symbol) = sym.is(Mutable, butNot = Accessor) || diff --git a/tests/neg/i16655.check b/tests/neg/i16655.check new file mode 100644 index 000000000000..e1335b624244 --- /dev/null +++ b/tests/neg/i16655.check @@ -0,0 +1,6 @@ +-- [E052] Type Error: tests/neg/i16655.scala:3:4 ----------------------------------------------------------------------- +3 | x = 5 // error + | ^^^^^ + | Reassignment to val x + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i16655.scala b/tests/neg/i16655.scala new file mode 100644 index 000000000000..c758678d9896 --- /dev/null +++ b/tests/neg/i16655.scala @@ -0,0 +1,3 @@ +object Test: + val x = "MyString" + x = 5 // error