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. --- test/files/neg/t6795.check | 4 ++++ test/files/neg/t6795.scala | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 test/files/neg/t6795.check create mode 100644 test/files/neg/t6795.scala (limited to 'test') 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 From f029c3a141972b23e33310e23db72e0e602a46ca Mon Sep 17 00:00:00 2001 From: James Iry Date: Mon, 10 Dec 2012 15:22:49 -0800 Subject: SI-6795 Simplify errors related to "abstract override" on type members Instead of saying "only allowed on non-type members of traits" use separate errors for "not allowed on types" and "only allowed on members of traits" --- src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 7 +++++-- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 8 ++++++-- test/files/neg/t6795.check | 2 +- test/files/neg/t6795.scala | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 9bceb91d4e..4268398081 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -980,7 +980,7 @@ trait ContextErrors { object SymValidateErrors extends Enumeration { val ImplicitConstr, ImplicitNotTermOrClass, ImplicitAtToplevel, OverrideClass, SealedNonClass, AbstractNonClass, - OverrideConstr, AbstractOverride, LazyAndEarlyInit, + OverrideConstr, AbstractOverride, AbstractOverrideOnTypeMember, LazyAndEarlyInit, ByNameParameter, AbstractVar = Value } @@ -1077,7 +1077,10 @@ trait ContextErrors { "`override' modifier not allowed for constructors" case AbstractOverride => - "`abstract override' modifier only allowed for non-type members of traits" + "`abstract override' modifier only allowed for members of traits" + + case AbstractOverrideOnTypeMember => + "`abstract override' modifier not allowed for type members" 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 c6eacf1fb7..98b6264051 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1443,8 +1443,12 @@ trait Namers extends MethodSynthesis { if (sym.isConstructor && sym.isAnyOverride) fail(OverrideConstr) - if (sym.isAbstractOverride && (!sym.owner.isTrait || sym.isType)) - fail(AbstractOverride) + if (sym.isAbstractOverride) { + if (!sym.owner.isTrait) + fail(AbstractOverride) + if(sym.isType) + fail(AbstractOverrideOnTypeMember) + } 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 index 595eda4f22..88ef3e9a52 100644 --- a/test/files/neg/t6795.check +++ b/test/files/neg/t6795.check @@ -1,4 +1,4 @@ -t6795.scala:3: error: `abstract override' modifier only allowed for non-type members of traits +t6795.scala:3: error: `abstract override' modifier not allowed for type members 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 index a93be5bc7f..a523c89c82 100644 --- a/test/files/neg/t6795.scala +++ b/test/files/neg/t6795.scala @@ -1,3 +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 +trait T1 extends T { abstract override type U = Int } -- cgit v1.2.3