Skip to content

Commit 6e9200a

Browse files
Merge pull request #6549 from dotty-staging/fix-error-ms
Fix error message when overriding with a lazy val
2 parents bb25f19 + 2d001bf commit 6e9200a

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ object RefChecks {
388388
} else if (member.is(ModuleVal) && !other.isRealMethod && !other.is(Deferred | Lazy)) {
389389
overrideError("may not override a concrete non-lazy value")
390390
} else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) &&
391-
!ctx.testScala2Mode("may not override a non-lazy value", member.sourcePos)) {
391+
!ctx.testScala2Mode(overrideErrorMsg("may not override a non-lazy value"), member.sourcePos)) {
392392
overrideError("may not override a non-lazy value")
393393
} else if (other.is(Lazy) && !other.isRealMethod && !member.is(Lazy)) {
394394
overrideError("must be declared lazy to override a lazy value")

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class CompilationTests extends ParallelTesting {
160160
compileFile("tests/neg-custom-args/implicit-conversions-old.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
161161
compileFile("tests/neg-custom-args/i3246.scala", scala2Mode),
162162
compileFile("tests/neg-custom-args/overrideClass.scala", scala2Mode),
163+
compileFile("tests/neg-custom-args/ovlazy.scala", scala2Mode.and("-migration", "-Xfatal-warnings")),
163164
compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")),
164165
compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")),
165166
compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")),

tests/neg-custom-args/ovlazy.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg-custom-args/ovlazy.scala:5:20 ----------------------------------------------------------------------
2+
5 | override lazy val x: Int = 2 // error
3+
| ^
4+
| error overriding value x in class A of type Int;
5+
| lazy value x of type Int may not override a non-lazy value

tests/neg-custom-args/ovlazy.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A {
2+
val x: Int = 1
3+
}
4+
class B extends A {
5+
override lazy val x: Int = 2 // error
6+
}

0 commit comments

Comments
 (0)