-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ValueEnums not working with private constructors (#67)
In 1.4.11, the macro started only looking for public constructor methods. There was no reason for this change at all, so it has been reverted.
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...atum-core/compat/src/test/scala-2.11/enumeratum/values/CustomEnumPrivateConstructor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package enumeratum.values | ||
|
||
/** | ||
* Code from @zifeo | ||
*/ | ||
trait CustomEnumEntry extends IntEnumEntry { | ||
val value: Int | ||
val name: String | ||
} | ||
trait CustomEnum[T <: CustomEnumEntry] extends IntEnum[T] { | ||
def apply(name: String): T = | ||
values.find(_.name == name).get | ||
} | ||
trait CustomEnumComparable[T <: CustomEnumEntry] { | ||
this: T => | ||
def >=(that: T): Boolean = | ||
this.value >= that.value | ||
} | ||
sealed abstract class CustomEnumPrivateConstructor private (val value: Int, val name: String) | ||
extends CustomEnumEntry with CustomEnumComparable[CustomEnumPrivateConstructor] | ||
object CustomEnumPrivateConstructor extends CustomEnum[CustomEnumPrivateConstructor] { | ||
val values = findValues | ||
case object A extends CustomEnumPrivateConstructor(10, "a") | ||
case object B extends CustomEnumPrivateConstructor(20, "b") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters