Skip to content

Commit

Permalink
Merge pull request #13744 from som-snytt/issue/13019
Browse files Browse the repository at this point in the history
Can mark var implementation as override
  • Loading branch information
smarter authored Oct 14, 2021
2 parents f031f2e + d45fbe8 commit c27107b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ object RefChecks {
overrideError("needs `override` modifier")
else if (other.is(AbsOverride) && other.isIncompleteIn(clazz) && !member.is(AbsOverride))
overrideError("needs `abstract override` modifiers")
else if (member.is(Override) && other.is(Accessor) &&
other.accessedFieldOrGetter.is(Mutable, butNot = Lazy))
else if member.is(Override) && other.is(Accessor, butNot = Deferred) && other.accessedFieldOrGetter.is(Mutable, butNot = Lazy) then
overrideError("cannot override a mutable variable")
else if (member.isAnyOverride &&
!(member.owner.thisType.baseClasses exists (_ isSubClass other.owner)) &&
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i13019.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

trait Ok1 { var i: Int }
class Ok1C extends Ok1 { var i: Int = 1 }

trait Ok2 {
def i: Int
def i_=(v: Int): Unit
}
class Ok2C extends Ok2 { override var i: Int = 1 }

// was: variable i of type Int cannot override a mutable variable
trait NotOk {var i: Int}
class NotOkC extends NotOk { override var i: Int = 1 }

0 comments on commit c27107b

Please sign in to comment.