Skip to content
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

Merged
merged 7 commits into from
May 12, 2021
Merged

Adapt validator macros #1225

merged 7 commits into from
May 12, 2021

Conversation

mbore
Copy link
Contributor

@mbore mbore commented May 11, 2021

No description provided.

@mbore mbore requested a review from adamw May 11, 2021 12:19
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.")
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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?

@adamw adamw merged commit 7f58408 into scala3 May 12, 2021
@mergify mergify bot deleted the adapt-validator-macros branch May 12, 2021 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants