Skip to content

Fix error message when overriding with a lazy val #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ object RefChecks {
} else if (member.is(ModuleVal) && !other.isRealMethod && !other.is(Deferred | Lazy)) {
overrideError("may not override a concrete non-lazy value")
} else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) &&
!ctx.testScala2Mode("may not override a non-lazy value", member.sourcePos)) {
!ctx.testScala2Mode(overrideErrorMsg("may not override a non-lazy value"), member.sourcePos)) {
overrideError("may not override a non-lazy value")
} else if (other.is(Lazy) && !other.isRealMethod && !member.is(Lazy)) {
overrideError("must be declared lazy to override a lazy value")
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class CompilationTests extends ParallelTesting {
compileFile("tests/neg-custom-args/implicit-conversions-old.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFile("tests/neg-custom-args/i3246.scala", scala2Mode),
compileFile("tests/neg-custom-args/overrideClass.scala", scala2Mode),
compileFile("tests/neg-custom-args/ovlazy.scala", scala2Mode.and("-migration", "-Xfatal-warnings")),
compileFile("tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")),
compileFile("tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")),
compileFile("tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")),
Expand Down
5 changes: 5 additions & 0 deletions tests/neg-custom-args/ovlazy.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Error: tests/neg-custom-args/ovlazy.scala:5:20 ----------------------------------------------------------------------
5 | override lazy val x: Int = 2 // error
| ^
| error overriding value x in class A of type Int;
| lazy value x of type Int may not override a non-lazy value
6 changes: 6 additions & 0 deletions tests/neg-custom-args/ovlazy.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class A {
val x: Int = 1
}
class B extends A {
override lazy val x: Int = 2 // error
}