diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 9 | ||||
-rw-r--r-- | test/files/neg/bug4882.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug4882.scala | 3 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 7a42d6e519..2ebfdc7426 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1343,6 +1343,13 @@ trait Namers { self: Analyzer => " for: " + sym); } + if (sym.isConstructor) { + if (sym.hasFlag(OVERRIDE | ABSOVERRIDE)) + context.error(sym.pos, "`override' modifier not allowed for constructors") + if (sym.isImplicit) + context.error(sym.pos, "`implicit' modifier not allowed for constructors") + } + if (sym.hasFlag(IMPLICIT) && !sym.isTerm) context.error(sym.pos, "`implicit' modifier can be used only for values, variables and methods") if (sym.hasFlag(IMPLICIT) && sym.owner.isPackageClass) @@ -1354,8 +1361,6 @@ trait Namers { self: Analyzer => "\nit should be omitted for abstract members") if (sym.hasFlag(OVERRIDE | ABSOVERRIDE) && !sym.hasFlag(TRAIT) && sym.isClass) context.error(sym.pos, "`override' modifier not allowed for classes") - if (sym.hasFlag(OVERRIDE | ABSOVERRIDE) && sym.isConstructor) - context.error(sym.pos, "`override' modifier not allowed for constructors") if (sym.hasFlag(ABSOVERRIDE) && !sym.owner.isTrait) context.error(sym.pos, "`abstract override' modifier only allowed for members of traits") if (sym.isLazy && sym.hasFlag(PRESUPER)) diff --git a/test/files/neg/bug4882.check b/test/files/neg/bug4882.check new file mode 100644 index 0000000000..2987cabe7f --- /dev/null +++ b/test/files/neg/bug4882.check @@ -0,0 +1,4 @@ +bug4882.scala:2: error: `implicit' modifier not allowed for constructors + implicit def this(a: String) = this(a.toInt) + ^ +one error found diff --git a/test/files/neg/bug4882.scala b/test/files/neg/bug4882.scala new file mode 100644 index 0000000000..4e58ef7879 --- /dev/null +++ b/test/files/neg/bug4882.scala @@ -0,0 +1,3 @@ +class Foo(value: Int) { + implicit def this(a: String) = this(a.toInt) +} |