diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-07-06 16:11:32 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-08-11 10:59:16 -0700 |
commit | 9b59f5f9530d54c917479c6bf44aa3007ba0a2df (patch) | |
tree | 5e31b6c4c8281e0f51b8f8cf7dcfd6b611a9f612 | |
parent | 16e7cf335bf9fbd7f68b043b9d670336c6897809 (diff) | |
download | scala-9b59f5f9530d54c917479c6bf44aa3007ba0a2df.tar.gz scala-9b59f5f9530d54c917479c6bf44aa3007ba0a2df.tar.bz2 scala-9b59f5f9530d54c917479c6bf44aa3007ba0a2df.zip |
Allow 'overriding' deferred var
Discovered by scala-js's test suite.
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 |