Skip to content

Commit

Permalink
Resolve #96 base case
Browse files Browse the repository at this point in the history
- Make the member trees search use  an iterator so we only grab the very first one
  • Loading branch information
lloydmeta committed Jan 4, 2017
1 parent 8f19ba9 commit f10e944
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
25 changes: 25 additions & 0 deletions enumeratum-core/src/test/scala/enumeratum/values/Compilation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package enumeratum.values

/**
* Created by Lloyd on 1/4/17.
*
* Copyright 2017
*/
// From https://github.com/lloydmeta/enumeratum/issues/96

sealed abstract class A private (val value: Int) extends IntEnumEntry {
val text: String
}

object A extends IntEnum[A] {

val values = findValues

case object A1 extends A(1) {
val text = identity("something") // Error:(9, 16) object A1 has a value with the wrong type: something:class java.lang.String, instead of int.
//val text = "something"
}

def identity(str: String) = str

}
5 changes: 3 additions & 2 deletions macros/src/main/scala/enumeratum/ValueEnumMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ object ValueEnumMacros {
val valueTerm = ContextUtils.termName(c)("value")
// go through all the trees
memberTrees.map { declTree =>
val values = declTree.collect {
val trees = declTree.collect { case t => t }.iterator
val values = trees.collect {
// The tree has a value declaration with a constant value.
case ValDef(_, termName, _, Literal(Constant(i: ValueType))) if termName == valueTerm =>
Some(i)
// The tree has a method call
case Apply(fun, args) => {
case Apply(_, args) => {
val valueArguments: List[Option[ValueType]] =
valueEntryCTorsParams.collect {
// Find the constructor params list that matches the arguments list size of the method call
Expand Down

0 comments on commit f10e944

Please sign in to comment.