From a9d2568b36c517b4691d2b5fcb60e6a8e30be3a5 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 10 Dec 2012 14:11:28 -0800 Subject: Fix for SI-6595, lost modifiers in early defs. Saw this by accident; the trees created for early defs would wholesale replace the modifiers with PRESUPER rather than combining them. FINAL was lost that way, as would be any other modifiers which might be valid there. --- src/compiler/scala/tools/nsc/ast/Trees.scala | 2 +- test/files/pos/t6595.flags | 1 + test/files/pos/t6595.scala | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t6595.flags create mode 100644 test/files/pos/t6595.scala diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index e796258967..f1556495ec 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -104,7 +104,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global => rhs = EmptyTree ) } - val lvdefs = evdefs collect { case vdef: ValDef => copyValDef(vdef)(mods = Modifiers(PRESUPER)) } + val lvdefs = evdefs collect { case vdef: ValDef => copyValDef(vdef)(mods = vdef.mods | PRESUPER) } val constrs = { if (constrMods hasFlag TRAIT) { diff --git a/test/files/pos/t6595.flags b/test/files/pos/t6595.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/pos/t6595.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/pos/t6595.scala b/test/files/pos/t6595.scala new file mode 100644 index 0000000000..437c0bcf05 --- /dev/null +++ b/test/files/pos/t6595.scala @@ -0,0 +1,18 @@ +import scala.annotation.switch + +class Foo extends { + final val b0 = 5 +} with AnyRef { + final val b1 = 10 + + // Using the @switch annotation as a means of testing that the + // type inferred for b0 is Int(5) and not Int. Only in the former + // case can a switch be generated. + def f(p: Int) = (p: @switch) match { + case `b0` => 1 + case `b1` => 2 + case 15 => 3 + case 20 => 4 + case _ => 5 + } +} -- cgit v1.2.3