-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt validator macros #1225
Adapt validator macros #1225
Conversation
val children = symbol.children.toList.sortBy(_.name) | ||
|
||
if (!children.forall(_.flags is Flags.Module) && !(symbol.flags is Flags.Enum)) { | ||
report.throwError("All children must be objects or enum cases.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum cases can also have parameters. So we should reject e.g.:
enum Color:
case Red(x: String)
but accept:
enum Color:
case Red
but maybe this is already covered? I think we'll need a scala3-specific test here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added test and improved error message for this scenario
|
||
enum ColorEnum { | ||
case Green extends ColorEnum | ||
case Pink extends ColorEnum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately we can't add enum
here, as this will now fail to compile with scala 2. We need to create a ValidatorTest2
(or sth like that ;) ) in the scala-3
source tree
@@ -107,17 +107,50 @@ class ValidatorTest extends AnyFlatSpec with Matchers { | |||
v(0) shouldBe List(ValidationError.Custom(0, "X has to be greater than 5!")) | |||
} | |||
|
|||
it should "validate enum" in { | |||
it should "validate coproduct enum" in { | |||
Validator.derivedEnumeration[Color](Blue) shouldBe empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe in fact we can do a better test here - examining the possibleValues
of the returned Validator.Enumeration
?
No description provided.