-
Notifications
You must be signed in to change notification settings - Fork 224
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
Comparisons should support constants #755
Comments
Hi there! I'd like to work on this issue but I have a couple questions first: Thanks so much for your help and great work, and apologies if these questions are unclear. |
Hi @mlfbrown, thanks for your message!
We support the constant keyword, but I mistakenly typed the wrong syntax the issue description. The proper way to use this is
Solidity only supports constants at contract level or outside them. The evaluation of their value is done during an AST traversal in Solang, not in constant folding. Any improvement to constant folding is welcome, and if you do so, please open a different PR because it is not related to this issue. |
Great, thanks for the info.
This is actually what was getting me on constant keyword support, not your syntax! I'll definitely keep constant folding changes to a separate PR. Thanks! |
I'd like to work on this issue! If I understand correctly, the goal is to transform statements like |
Not exactly during parsing. The AST should contain the original expression as it appears in the source code. There is a function |
…tion This patch supports evaluation of comparison expressions with constants as operands during compile time. Fixes hyperledger-solang#755
…tion This patch supports evaluation of comparison expressions with constants as operands during compile time. Fixes hyperledger-solang#755 Signed-off-by: Nirhar <[email protected]>
When we declare a constant variable that has an initializer, e.g.
bool constant x = 0 < 2
, we evaluate the actual constant value in compiler time. Currently, there is no support to evaluate constants in comparisons, so the aforementioned example is evaluated in run time.We need to calculate comparisons with constants during compilation. The
eval_const_number
function should becomeeval_const_expression
to evaluate boolean operators too. This function should be called atfn var_decl
insrc/sema/variables.rs
so that the initializer of a constant is evaluated at compile time.The text was updated successfully, but these errors were encountered: