aboutsummaryrefslogtreecommitdiff
path: root/core/shared/src/main/scala
diff options
context:
space:
mode:
authorLeandro Bolivar <leandrob131@gmail.com>2017-11-25 11:29:20 -0500
committerLeandro Bolivar <leandrob131@gmail.com>2017-11-25 11:29:20 -0500
commit2de22e7d27025f839ef70916d3bfb99e69973521 (patch)
treea44b296d5f5bf5c85f69f62c4f1723fdcb9bf868 /core/shared/src/main/scala
parentf336d9593acf3e9a95ce5a96b0631dd00f993197 (diff)
downloadmagnolia-2de22e7d27025f839ef70916d3bfb99e69973521.tar.gz
magnolia-2de22e7d27025f839ef70916d3bfb99e69973521.tar.bz2
magnolia-2de22e7d27025f839ef70916d3bfb99e69973521.zip
Fixed error that ocurred when the companion object of a case class has alternative apply methods
Diffstat (limited to 'core/shared/src/main/scala')
-rw-r--r--core/shared/src/main/scala/magnolia.scala10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index 6400002..337edc7 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -279,9 +279,15 @@ object Magnolia {
val defaults = if (!isValueClass) {
val caseClassCompanion = genericType.companion
- val constructorMethod = caseClassCompanion.decl(TermName("apply")).asMethod
+ // If a companion object is defined with alternative apply methods
+ // it is needed get all the alternatives
+ val constructorMethod =
+ caseClassCompanion.decl(TermName("apply")).alternatives.map(_.asMethod)
+
+ // The last apply method in the alternatives is the one that belongs
+ // to the case class, not the user defined companion object
val indexedConstructorParams =
- constructorMethod.paramLists.head.map(_.asTerm).zipWithIndex
+ constructorMethod.last.paramLists.head.map(_.asTerm).zipWithIndex
indexedConstructorParams.map {
case (p, idx) =>