Deprecate the var keyword in SyntaxChecker#3425
Deprecate the var keyword in SyntaxChecker#3425chriseth merged 3 commits intoargotorg:developfrom jevogel:3301
Conversation
|
Thank you! Can you please add test cases (in |
|
Sure. Should I do anything about the existing test cases that are failing due to their use of |
|
Please fix them :) The ones which are specifically made to test In cases it is used by mistake, it should be replaced with a proper type (probably there aren't any cases of this). |
|
I wonder whether it might be better to already do that at parsing time, but I guess the problem is that we do not yet have access to the pragma at that point - is that correct? |
|
Yes, pragma is evaluated later. But this should be fine. |
|
I edited all test cases that were failing to check for the If you could take a look at the changes and let me know which test cases should be reworked, I can take a shot at it. |
| contract B is A { } | ||
| )"; | ||
| // Error (TypeError): Definition of base has to precede definition of derived contract | ||
| // Warning: Use of var keyword is deprecated |
There was a problem hiding this comment.
Why did you put this here?
There was a problem hiding this comment.
Not sure how that got in there, but I'll get rid of it.
| } | ||
| } | ||
| )"; | ||
| CHECK_WARNING(sourceCode, "uint8, which can hold values between 0 and 255"); |
There was a problem hiding this comment.
It should be checked that this error message is present until we disallow var completely.
There was a problem hiding this comment.
Can you clarify? CHECK_WARNING_ALLOW_MULTI seems to only allow the first warning to be checked, so if var is used in this test it will cause the first warning and it will not be possible to check for the size warning. Is there a way to check both?
There was a problem hiding this comment.
I fear someone has to extend the macro...
There was a problem hiding this comment.
I could look into this within the next week or so. Do you want to file it as a separate issue?
| } | ||
| } | ||
| )"; | ||
| CHECK_WARNING(text, "\"callcode\" has been deprecated in favour of \"delegatecall\""); |
There was a problem hiding this comment.
You can replace var with bool in this example.
There was a problem hiding this comment.
Changing var to bool here gives me the message
Type function () payable returns (bool) is not implicitly convertible to expected type bool.
There was a problem hiding this comment.
You might be able to go with just function f() pure public { address(0x12).callcode; } for now.
There was a problem hiding this comment.
OK, then probably best to just remove the variable.
| @@ -4838,7 +4850,10 @@ BOOST_AUTO_TEST_CASE(warn_about_callcode) | |||
| } | |||
| } | ||
| )"; | ||
| CHECK_SUCCESS_NO_WARNINGS(text); | ||
| CHECK_WARNING(text, "Use of var keyword is deprecated"); |
There was a problem hiding this comment.
function pure external g = this.h should work
There was a problem hiding this comment.
Looks like the next block below tests this exactly, so I'll just remove this block.
| @@ -6817,7 +6832,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig) | |||
| } | |||
There was a problem hiding this comment.
I think you don't modify the test by adding a type for i.
| } | ||
| } | ||
| )"; | ||
| CHECK_WARNING(text, "\"sha3\" has been deprecated in favour of \"keccak256\""); |
There was a problem hiding this comment.
Please replace var by bytes32
| // Error (TypeError): | ||
| // Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view" | ||
| CHECK_WARNING_ALLOW_MULTI( | ||
| "contract C { function f() pure public { var x = " + x + "; x; } }", |
There was a problem hiding this comment.
This is a tricky one. Perhaps you could turn this vector of expressions into a vector of pairs of expressions and their type, but it might not work for all of them because some types do not have a name.
There was a problem hiding this comment.
I took a stab at this but ran into some problems. Maybe you can spot the root cause? gist.
| function() payable public {} | ||
| } | ||
| )"; | ||
| CHECK_SUCCESS_NO_WARNINGS(text); |
There was a problem hiding this comment.
Please replace var by the proper types here.
|
Made some progress on fixing the tests, but ran into some problems with the |
|
I am a git noob and inadvertently polluted this pull request with a ton of commits from |
|
Please don't close. Just run Assuming you're local git copy has |
|
I did the rebase but all of the commits are still showing up in the history of this PR. Is that a problem? |
|
It seems to be correct for me. Refresh github a few times, sometimes it can take a while. |
|
Awesome, that worked. Thanks for your patience! |
|
Started #3479 to allow searching in a set of errors. |
|
All tests should work now, but we still need to take a look at the expectations: Some tests now search for "var is deprecated", although what they actually should do is check that there is no other warning apart from "var is deprecated". We should change the 'multi-error' feature such that we list all errors/warnings that occur (i.e. the exact same set), and not only search for one to be present. |
test/libsolidity/ViewPureChecker.cpp
Outdated
| { | ||
| CHECK_ERROR( | ||
| "contract C { function f() pure public { var x = " + x + "; x; } }", | ||
| "contract C { function f() pure public { " + x + "; } }", |
There was a problem hiding this comment.
The code was initially like that to avoid the "statement does not have an effect" warning, but it seems to be no problem.
|
Rebased onto the new multi-error testing framework. Will adjust the expectations tomorrow. |
|
@chriseth was it intended to drop all the other changes it had? I assume all of that was obsoleted by the new framework. |
|
Yes, it was intended, I would rather restart adding the expectations instead of going back and forth in the previous commits. |
|
Made the bear minimum changes required in tests. Many other tests could be cleaned up too. |
Fix #3301 by extending
libsolidity/analysis/SyntaxCheckerwith a visitor forVariableDeclarationwhere thetypeNameis empty (means "var"). The compiler emits a warning for such instances, unless the experimental mode V050 is turned on, in which case it emits an error. This addition causes 7 errors in SolidityTests due to their use of thevarkeyword.