aboutsummaryrefslogtreecommitdiff
path: root/core/shared/src/main
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-11-29 15:24:19 +0100
committerGitHub <noreply@github.com>2017-11-29 15:24:19 +0100
commit376c06cb95106de60319a4d62268a94951aab084 (patch)
tree791c5d01e21701a4f28d5ea764ad19a07bdc18bf /core/shared/src/main
parent2332d33b0da2861e958a313bbd1707ab0ce289db (diff)
parent615af3df03f9079691f6aec5992671ae2c08dac9 (diff)
downloadmagnolia-376c06cb95106de60319a4d62268a94951aab084.tar.gz
magnolia-376c06cb95106de60319a4d62268a94951aab084.tar.bz2
magnolia-376c06cb95106de60319a4d62268a94951aab084.zip
Merge pull request #48 from leandrob13/fix/errorWithAlternativeApplyMethods
Fixed derivation error when companion has alternative apply methods
Diffstat (limited to 'core/shared/src/main')
-rw-r--r--core/shared/src/main/scala/magnolia.scala11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala
index d400bc3..9af9b09 100644
--- a/core/shared/src/main/scala/magnolia.scala
+++ b/core/shared/src/main/scala/magnolia.scala
@@ -280,9 +280,16 @@ 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 constructorMethods =
+ 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
+ constructorMethods.last.paramLists.head.map(_.asTerm).zipWithIndex
indexedConstructorParams.map {
case (p, idx) =>