For information / discussion: Add support for Scala 3 enums #1176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
Fixes
Fixes #1017.
However, it does so using Scala 3's Mirror.Sum. This forbids any subclasses which are not products or sums themselves.
This is why the test for
knownSubclassesis failing -TestUnion.UThas a subclassUCwhich is a normal class.Purpose
This PR adds support for Scala 3
enums.Background Context
The problem with the current implementation is that it assumes that the
.childrenof aTypeReprwill be subclasses of thatTypeRepr.Scala 3
enumcases are encoded asvals which are bound to an anonymous class. They are ascribed with the type of the parent definition.For example:
This causes the
subclassesfunction of theknownSubclasseshelper to loop indefinitely trying to find the subclasses ofColorbecause thetpt.tpeof theValDefchildren is the sameTypeReprforColorthat we started with. This is the cause for #1019.I do not know how to get the singleton
TypeReprof theenumcasefrom theValDef, but I think that would be the way to solve this problem while preserving the existing behaviour of the macro.References
Scala 3 Enumerations Implementation