diff options
4 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 7021e12f1a..674e0051b4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -433,7 +433,7 @@ abstract class RefChecks extends Transform { } else if (other.isAbstractOverride && other.isIncompleteIn(clazz) && !member.isAbstractOverride) { overrideError("needs `abstract override' modifiers") } - else if (member.isAnyOverride && (other hasFlag ACCESSOR) && !(other hasFlag STABLE)) { + else if (member.isAnyOverride && (other hasFlag ACCESSOR) && !(other hasFlag STABLE | DEFERRED)) { // The check above used to look at `field` == `other.accessed`, ensuring field.isVariable && !field.isLazy, // which I think is identical to the more direct `!(other hasFlag STABLE)` (given that `other` is a method). // Also, we're moving away from (looking at) underlying fields (vals in traits no longer have them, to begin with) diff --git a/test/files/neg/trait_fields_var_override.check b/test/files/neg/trait_fields_var_override.check new file mode 100644 index 0000000000..7245c78b09 --- /dev/null +++ b/test/files/neg/trait_fields_var_override.check @@ -0,0 +1,5 @@ +trait_fields_var_override.scala:2: error: overriding variable end in trait SizeChangeEvent of type Int; + variable end cannot override a mutable variable +class BackedUpListIterator[E](override protected var end: Int) extends SizeChangeEvent + ^ +one error found diff --git a/test/files/neg/trait_fields_var_override.scala b/test/files/neg/trait_fields_var_override.scala new file mode 100644 index 0000000000..f61ba09eec --- /dev/null +++ b/test/files/neg/trait_fields_var_override.scala @@ -0,0 +1,2 @@ +trait SizeChangeEvent { protected var end: Int = 1 } +class BackedUpListIterator[E](override protected var end: Int) extends SizeChangeEvent diff --git a/test/files/pos/trait_fields_var_override_deferred.scala b/test/files/pos/trait_fields_var_override_deferred.scala new file mode 100644 index 0000000000..0205326506 --- /dev/null +++ b/test/files/pos/trait_fields_var_override_deferred.scala @@ -0,0 +1,2 @@ +trait SizeChangeEvent { protected var end: Int } +class BackedUpListIterator[E](override protected var end: Int) extends SizeChangeEvent |