Skip to content

Possible regression in refchecks when overriding a mutable variable #15232

Closed
@KacperFKorban

Description

@KacperFKorban

Compiler version

3.1.3-RC3, 3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY

(compiles correctly on 3.1.2, 3.0.2, and 2.13.8)

Minimized code

//> using scala "3.1.3-RC3"
// //> using scala "3.1.2" // works
// //> using scala "3.0.2" // works
// //> using scala "2.13.8" // works

abstract trait A {
  var value: Int
}

abstract trait B {
  def value: Int = ???
}

class C extends A with B {
  override def value: Int = ???
  def value_=(newValue: Int): Unit = ???
}

Output

[error] ./main.scala:14:16: error overriding variable value in trait A of type Int;
[error]   method value of type => Int cannot override a mutable variable
[error]   override def value: Int = ???
[error]                ^

Expectation

Compile correctly

Additional info

This is most likely related to issue #14722 and PR that fixed it #14724

Also, note that the following code throws an error too

abstract trait A {
  var value: Int
}

class C extends A {
  override def value: Int = ???
  override def value_=(newValue: Int): Unit = ???
}

namely

[error] ./main.scala:11:16: error overriding variable value in trait A of type Int;
[error]   method value of type => Int cannot override a mutable variable
[error]   override def value: Int = ???
[error]                ^
[error] ./main.scala:12:16: error overriding variable value in trait A of type Int;
[error]   method value_= of type (newValue: Int): Unit cannot override a mutable variable
[error]   override def value_=(newValue: Int): Unit = ???
[error]                ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions