Fix isConstant (and other expression annotations) missing from Identifier nodes in AST JSON export#16482
Fix isConstant (and other expression annotations) missing from Identifier nodes in AST JSON export#16482
isConstant (and other expression annotations) missing from Identifier nodes in AST JSON export#16482Conversation
isConstant (and other expression annotations) missing from Identifier nodes in AST JSON export
dd6fe62 to
a2a28bf
Compare
…ier nodes Refactor visit(Identifier) in ASTJsonExporter to call appendExpressionAttributes() instead of manually enumerating fields. This ensures isConstant, isLValue, isPure, and lValueRequested annotations are properly exported to JSON. Co-authored-by: rodiazet <7524020+rodiazet@users.noreply.github.com>
Update existing test fixtures and add new constant_identifier test case to verify that Identifier nodes now correctly export isConstant, isLValue, isPure, and lValueRequested fields.
a2a28bf to
77d1571
Compare
rodiazet
left a comment
There was a problem hiding this comment.
LGTM. I updated cmdlineTests and remove .gitignore changes, as we already have build*path in .gitignore file. Also reorganised commits
Analysis CompleteExpression-derived types in AST:Direct Expression derivatives:
PrimaryExpression derivatives: Findings:✅ All Expression-derived types with visit methods properly call
|
There was a problem hiding this comment.
I'd use an AST property test for this. Those are less verbose and this is a case where are we're specifically interested in specific attributes and their values rather than the overall structure of the produced AST.
There was a problem hiding this comment.
The PR needs a changelog entry.
Yes, it's intentional. |
|
This pull request is stale because it has been open for 14 days with no activity. |
|
This pull request was closed due to a lack of activity for 7 days after it was stale. |
Identifiernodes in the exported JSON AST were missingisConstant,isLValue,isPure, andlValueRequested— even though these annotations are correctly computed during analysis. As a result, constant variable references always appeared to have no annotation at all rather than"isConstant": true.Root cause
visit(Identifier const& _node)inASTJsonExporter.cppwas manually setting onlytypeDescriptionsandargumentTypes, never callingappendExpressionAttributes()— unlike every other expression node visitor.Changes
libsolidity/ast/ASTJsonExporter.cpp: Refactorvisit(Identifier const& _node)to callappendExpressionAttributes()instead of manually enumerating fields, matching the pattern used by all other expression visitors.isConstant,isLValue,isPure, andlValueRequestedfields on Identifier nodes.constant_identifier.sol/constant_identifier.json: Covers the exact reported case — identifiers referencingconstantvariables should emit"isConstant": true.Example
Before (Identifier nodes had no expression annotation fields):
{ "name": "X", "nodeType": "Identifier", "typeDescriptions": { ... } }After:
{ "isConstant": true, "isLValue": false, "isPure": true, "lValueRequested": false, "name": "X", "nodeType": "Identifier", "typeDescriptions": { ... } }Original prompt
isConstantannotation in the AST is always false #16419