Permalink
Browse files

SI-7979 Fix quasiquotes crash on mismatch between fields and constructor

  • Loading branch information...
1 parent 0ccd4bc commit 26a33482718dc165ed5f9c4703205c94b9d0c058 @densh densh committed Dec 2, 2013
@@ -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)
}
}
}
@@ -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 =>

0 comments on commit 26a3348

Please sign in to comment.