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

Refactor reused enum-based macros #3208

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Refactor reused enum-based macros #3208

merged 3 commits into from
Sep 28, 2023

Conversation

kciesielski
Copy link
Member

Resolves #3206
This part moves isScalaEnum[T] from json-pickler to core internals for potential reuse. It also extracts the part that checks for object/enum children.
By the way, I noticed that the implementation I had in json-pickler wasn't recursive like the implementation used in ValidationMacros. Now it's the common one used, with a parameter that tells whether to fail if an unexpected child flag is found.

I could not think of any example to represent a nested case to test the actual recursion. Any ideas? :)


private[tapir] object EnumMacros:

transparent inline def isScalaEnum[T]: Boolean = inline compiletime.erasedValue[T] match
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name can be confusing, because this checks for more than a simple scala enum.

Maybe we could assume the following convention, using the name "enum" for all cases of Scala 3 enums (with or without parameters). On the other hand "enumeration" would mean "true" enumerations, that is parameterless enums or sealed traits with only case objects as children. It's not perfect as one is an abbrievation of the other, but I think if used consistently (we would probably need to document it in some developer docs - maybe readme?) it would be clear what we mean.

Copy link
Member Author

@kciesielski kciesielski Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I propose 'contributing.md' for such documentation. It also looks like a good place for versioning scheme #3111, wdyt?
Actually, versioning scheme should be in stability.md, it's something that may be interesting to users, not only contributors.

@adamw adamw merged commit 7174c40 into master Sep 28, 2023
@mergify mergify bot deleted the is-scala-enum branch September 28, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move isScalaEnum to core/internal
2 participants