Skip to content

Prefix not checked in realizability check for non-final lazy val #5521

Closed
@abeln

Description

@abeln
  1 class Hello {
  2   class Foo {
  3     class Bar
  4     final lazy val s: Bar = ???
  5   }
  6 
  7   lazy val foo: Foo = ???
  8 
  9   val x: foo.s.type = ???
 10   val x2: foo.s.type = ???
 11 }

Expected: both line 9 and 10 produce an error.

Actual: only line 10 produces an error:

10 |  val x2: foo.s.type = ???
   |              ^
   |              Hello.this.foo.Bar(Hello.this.foo.s) is not a legal path
   |              since it refers to nonfinal lazy value foo

The reason is the cached and uncached cases are handled differently in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala#L80
The uncached case doesn't check the prefix (hence why only the second time we try to use the same invalid path errors out).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions