Closed alexfertel closed 11 months ago
The parser is correct here: it cannot know that _
is a placeholder statement. In regular functions, you can have a variable called _
. This is determined during semantic analysis. The problem here is that the code formatter does follow an expression statement with a ;
, fixed in #1601
In regular functions, you can have a variable called _.
I tried declaring one in Remix, but couldn't:
You can see on the second screenshot that _
is a reserved name, so I don't think you can have variables named like that.
This is determined during semantic analysis.
Could you expand on this? Do you mean that the semantic analysis phase is what determines if _
is a placeholder statement or not?
The problem here is that the code formatter does follow an expression statement with a ;, fixed in https://github.com/hyperledger/solang/pull/1601
Nice! I think that works 👍🏻.
I tried declaring one in Remix, but couldn't:
If you select solc 0.5 or 0.6 it works fine. Every solc release, a bunch of minor things are changed which breaks backwards compatibility.
Could you expand on this? Do you mean that the semantic analysis phase is what determines if
_
is a placeholder statement or not?
Yes, the parser generates a parse tree based of the grammar. The semantic analysis stage resolves all the variables and functions calls (and much more).
Problem
tl;dr
_;
gets parsed as anExpression::Variable
, which means that when the parse tree is formatted usingDisplay
, it gets emitted as_
, without the trailing semicolon. Since https://github.com/ethereum/solidity/releases/tag/v0.4.0,_
must be followed by a;
.Repro
Given this contract:
The formatted representation of the parse tree is:
Solution
Statement::VariableDefinition
, like so:since the
Display
implementation of this node does append a;
.Statement::Placeholder
node, which represents a_;
statement._
in the display implementation.