Skip to content

The meaning of this.field in class body #15723

Closed
@liufengyun

Description

@liufengyun

Compiler version

Scala 2 and Scala 3 (master)

Minimized code

class B(val y: Int):
  println(this.y)
  foo()
  def foo() = println(this.y)

class C(override val y: Int) extends B(10)

@main
def Test = new C(20)

Output

10
20

Expectation

I would expect this.y to have the same semantics both in the class body and method body.

It's up to discussion whether an unqualified y in class body and in method body should have the same semantics.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions