diff --git a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala index 774cc233bff8..788b6d474999 100644 --- a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala +++ b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala @@ -74,11 +74,13 @@ class CheckRealizable(implicit ctx: Context) { else { val r = if (!sym.isStable) NotStable - else if (!isLateInitialized(sym)) realizability(tp.prefix) + else if (!isLateInitialized(sym)) Realizable else if (!sym.isEffectivelyFinal) new NotFinal(sym) else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r)) - if (r == Realizable) sym.setFlag(Stable) - r + r andAlso { + sym.setFlag(Stable) + realizability(tp.prefix) + } } case _: SingletonType | NoPrefix => Realizable diff --git a/tests/neg/i5521.scala b/tests/neg/i5521.scala new file mode 100644 index 000000000000..9edb43605036 --- /dev/null +++ b/tests/neg/i5521.scala @@ -0,0 +1,12 @@ +class Hello { + class Foo { + class Bar + final lazy val s: Bar = ??? + } + + lazy val foo: Foo = ??? + + val x: foo.s.type = ??? // error: `foo` must be final since it's a lazy val + val x2: foo.s.type = ??? // error: `foo` must be final since it's a lazy val +} +