diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-02 15:30:22 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-12-10 16:02:44 +0100 |
commit | 26a33482718dc165ed5f9c4703205c94b9d0c058 (patch) | |
tree | 307f784b261ff32d1aff44d6a26796aa163e9599 | |
parent | 0ccd4bcac64efe72d9758fbfb6a6dbce44cf308e (diff) | |
download | scala-26a33482718dc165ed5f9c4703205c94b9d0c058.tar.gz scala-26a33482718dc165ed5f9c4703205c94b9d0c058.tar.bz2 scala-26a33482718dc165ed5f9c4703205c94b9d0c058.zip |
SI-7979 Fix quasiquotes crash on mismatch between fields and constructor
-rw-r--r-- | src/reflect/scala/reflect/internal/BuildUtils.scala | 12 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala | 16 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index 22e2bf4cad..357109ac2c 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -212,11 +212,15 @@ trait BuildUtils { self: SymbolTable => } // undo flag modifications by mergeing flag info from constructor args and fieldDefs val modsMap = fieldDefs.map { case ValDef(mods, name, _, _) => name -> mods }.toMap - val vparamss = mmap(vparamssRestoredImplicits) { vd => - val originalMods = modsMap(vd.name) | (vd.mods.flags & DEFAULTPARAM) - atPos(vd.pos)(ValDef(originalMods, vd.name, vd.tpt, vd.rhs)) + def ctorArgsCorrespondToFields = vparamssRestoredImplicits.flatten.forall { vd => modsMap.contains(vd.name) } + if (!ctorArgsCorrespondToFields) None + else { + val vparamss = mmap(vparamssRestoredImplicits) { vd => + val originalMods = modsMap(vd.name) | (vd.mods.flags & DEFAULTPARAM) + atPos(vd.pos)(ValDef(originalMods, vd.name, vd.tpt, vd.rhs)) + } + result(ctorMods, vparamss, edefs, body) } - result(ctorMods, vparamss, edefs, body) } } } diff --git a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala index dbd26bf72a..94465930ed 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala @@ -88,6 +88,22 @@ trait ClassDeconstruction { self: QuasiquoteProperties => matches("class Foo { self => bar(self) }") matches("case class Foo(x: Int)") } + + property("SI-7979") = test { + val PARAMACCESSOR = (1 << 29).toLong.asInstanceOf[FlagSet] + assertThrows[MatchError] { + val build.SyntacticClassDef(_, _, _, _, _, _, _, _, _) = + ClassDef( + Modifiers(), TypeName("Foo"), List(), + Template( + List(Select(Ident(TermName("scala")), TypeName("AnyRef"))), + noSelfType, + List( + //ValDef(Modifiers(PRIVATE | LOCAL | PARAMACCESSOR), TermName("x"), Ident(TypeName("Int")), EmptyTree), + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List(ValDef(Modifiers(PARAM | PARAMACCESSOR), TermName("x"), + Ident(TypeName("Int")), EmptyTree))), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(()))))))) + } + } } trait ModsDeconstruction { self: QuasiquoteProperties => |