Permalink
Browse files

Fix extraction when case class has a companion object (fixes 1073)

  • Loading branch information...
1 parent 9d850e7 commit 3a110ba923ab7265140d15e0fab5aeccb89a65e1 Joni Freeman committed Aug 10, 2011
@@ -22,7 +22,7 @@ import scala.tools.scalap.scalax.rules.scalasig._
private[json] object ScalaSigReader {
def readConstructor(argName: String, clazz: Class[_], typeArgIndex: Int, argNames: List[String]): Class[_] = {
val cl = findClass(clazz)
- val cstr = findConstructor(cl, argNames).getOrElse(Meta.fail("Can't find constructor " + clazz))
+ val cstr = findConstructor(cl, argNames).getOrElse(Meta.fail("Can't find constructor for " + clazz))
findArgType(cstr, argNames.indexOf(argName), typeArgIndex)
}
@@ -42,7 +42,7 @@ private[json] object ScalaSigReader {
}
private def findClass(sig: ScalaSig, clazz: Class[_]): Option[ClassSymbol] = {
- sig.symbols.collect { case c: ClassSymbol => c }.find(_.name == clazz.getSimpleName).orElse {
+ sig.symbols.collect { case c: ClassSymbol if !c.isModule => c }.find(_.name == clazz.getSimpleName).orElse {
sig.topLevelClasses.find(_.symbolInfo.name == clazz.getSimpleName).orElse {
sig.topLevelObjects.map { obj =>
val t = obj.infoType.asInstanceOf[TypeRefType]
@@ -48,6 +48,10 @@ object ExtractionBugs extends Specification("Extraction bugs Specification") {
parse("""{"foo.bar,baz":"x"}""").extract[UnicodeFieldNames] mustEqual UnicodeFieldNames("x")
}
+ "Extraction should not fail if case class has a companion object" in {
+ parse("""{"nums":[10]}""").extract[HasCompanion] mustEqual HasCompanion(List(10))
+ }
+
case class OptionOfInt(opt: Option[Int])
case class PMap(m: Map[String, List[String]])
@@ -61,4 +65,9 @@ object ExtractionBugs extends Specification("Extraction bugs Specification") {
case class ExtractWithAnyRef()
case class UnicodeFieldNames(`foo.bar,baz`: String)
+
+ object HasCompanion {
+ def hello = "hello"
+ }
+ case class HasCompanion(nums: List[Int])
}

0 comments on commit 3a110ba

Please sign in to comment.