From 71e42a799aa11fda75d9d3e7b92da9f61dd1da5b Mon Sep 17 00:00:00 2001 From: James Iry Date: Mon, 10 Dec 2012 14:49:23 -0800 Subject: SI-6795 Adds negative check for "abstract override" on types in traits "abstract override" shouldn't was being allowed on types in traits but the result made no sense and the spec says that shouldn't be allowed. --- src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 2 +- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 4 ++-- test/files/neg/t6795.check | 4 ++++ test/files/neg/t6795.scala | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 test/files/neg/t6795.check create mode 100644 test/files/neg/t6795.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index ae3b0bc0b7..9bceb91d4e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -1077,7 +1077,7 @@ trait ContextErrors { "`override' modifier not allowed for constructors" case AbstractOverride => - "`abstract override' modifier only allowed for members of traits" + "`abstract override' modifier only allowed for non-type members of traits" case LazyAndEarlyInit => "`lazy' definitions may not be initialized early" diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 3f546c9a51..c6eacf1fb7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1443,8 +1443,8 @@ trait Namers extends MethodSynthesis { if (sym.isConstructor && sym.isAnyOverride) fail(OverrideConstr) - if (sym.isAbstractOverride && !sym.owner.isTrait) - fail(AbstractOverride) + if (sym.isAbstractOverride && (!sym.owner.isTrait || sym.isType)) + fail(AbstractOverride) if (sym.isLazy && sym.hasFlag(PRESUPER)) fail(LazyAndEarlyInit) if (sym.info.typeSymbol == FunctionClass(0) && sym.isValueParameter && sym.owner.isCaseClass) diff --git a/test/files/neg/t6795.check b/test/files/neg/t6795.check new file mode 100644 index 0000000000..595eda4f22 --- /dev/null +++ b/test/files/neg/t6795.check @@ -0,0 +1,4 @@ +t6795.scala:3: error: `abstract override' modifier only allowed for non-type members of traits +trait T1 extends T { abstract override type U = Int } + ^ +one error found diff --git a/test/files/neg/t6795.scala b/test/files/neg/t6795.scala new file mode 100644 index 0000000000..a93be5bc7f --- /dev/null +++ b/test/files/neg/t6795.scala @@ -0,0 +1,3 @@ +trait T { type U } +// "abstract override" shouldn't be allowed on types +trait T1 extends T { abstract override type U = Int } \ No newline at end of file -- cgit v1.2.3