Syntactic support for PHP enums#23
Merged
Merged
Conversation
Enums are by design a closed list, which inheritance would violate. Interfaces are allowed, but not parent classes.
thekid
commented
Mar 8, 2021
|
|
||
| $decl= new EnumDeclaration([], $name, $implements, [], [], $comment, $token->line); | ||
| $parse->expecting('{', 'enum'); | ||
| $decl->body= $this->typeBody($parse, $decl->name); |
Member
Author
There was a problem hiding this comment.
This is not completely correct, as typeBody() allows properties, which PHP enums do not. The RFC states this:
Specifically, the following features of objects are not allowed on enumerations: [...] Enum/Case properties - Properties are a form of state, and enum cases are stateless singletons. Metadata about an enum or case can always be exposed via methods.
Member
Author
There was a problem hiding this comment.
We'll leave this as-is, the compiler may chose to raise errors about this; or we simply leave it to the PHP runtime.
thekid
added a commit
to xp-framework/compiler
that referenced
this pull request
Mar 10, 2021
thekid
commented
Mar 12, 2021
https://wiki.php.net/rfc/enumerations#grouped_syntax states that this "may cause syntactic issues with the planned addition of tagged unions", which are defined in https://wiki.php.net/rfc/tagged_unions and may be one of the following: case None { } case Some(private mixed $value) { ... } ...in addition to the existing declarations: case ASC; case DESC = "desc"; In none of these case would a comma be ambiguous, therefore I think we might as well have it, thus allowing more concise syntax for enum declarations
Member
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See xp-framework/compiler#100
Unit enums
Backed enums
Grouped syntax
https://wiki.php.net/rfc/enumerations#grouped_syntax states that this "may cause syntactic issues with the planned addition of tagged unions", which are defined in https://wiki.php.net/rfc/tagged_unions and may be one of the following:
case None { }case Some(private mixed $value) { ... }...in addition to the existing declarations:
case ASCcase DESC = 'desc'In none of these cases would a comma be ambiguous, therefore I think we might as well have it, thus allowing more concise syntax for enum declarations