-
Notifications
You must be signed in to change notification settings - Fork 72
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
Fix Typed Class Constants parsing #1140
Conversation
"line": 31, | ||
"offset": 544, | ||
}, | ||
}, | ||
"name": Identifier { |
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.
It looks as though the source code location is lost during parsing as well
"attrGroups": [ | ||
AttrGroup { | ||
"attrs": [ | ||
Attribute { | ||
"args": [], | ||
"kind": "attribute", | ||
"name": "B", | ||
}, | ||
], | ||
"kind": "attrgroup", | ||
}, | ||
], |
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.
Attribute groups are lost too
AttrGroup { | ||
"attrs": [ | ||
Attribute { | ||
"args": [], | ||
"kind": "attribute", | ||
"name": "B", | ||
}, | ||
], | ||
"kind": "attrgroup", | ||
}, |
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.
This does not make sense either, nullable should be a bool value? looks like attrGroups and nullable are switched around somewhere
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.
It looks like the refactor has significantly changed the AST output around attrgroups, as the attrGroups should not be affected, also I would expect nullable to be a boolean type.
I figured out the core issue: the AST ClassConstant object
The code is reading a list of constant, to support this syntax. class Foo {
const PRI1 = 'baz', PRI2 = 'baz2';
} But the implementations made the assumption that all constant have the same type/nullable: type and nullable was added to "ClassConstant", not "Constant". That's incorect, because this code is valid: class Foo {
private const PRI1 = 'baz', string PRI2 = 'baz2', int PRI3 = 5;
} The last commit I pushed, 94d4069 keep the type on the "ClassConstant" object and create only 1 constant object per ClassConstant. That works, but it is a less accurate representation of the code being parsed. Now I am going to fix that by moving the type to the AST "Constant" object. |
@@ -53,6 +57,8 @@ Program { | |||
"kind": "identifier", | |||
"name": "CONSTANT", | |||
}, | |||
"nullable": null, | |||
"type": undefined, |
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.
If we do not want those to be part of the AST, we need to completly decouple the ClassConstant object from the Constant object.
@cseufert code is ready for another review |
Actually, they are still bug. I will reopen when it is fully ready. |
Fix #1133