Conversation
8e180f5 to
d98bc4b
Compare
|
What should be the semantics of the following snippet? With the current scoping, it will create an error, but only a warning with the new scoping, because in the new scoping, it is shadowing and not redeclaring. With the current implementation, though, the assignment |
|
It is debatable whether we want to support shadowing.
That sounds like a bug. |
|
Yes, I hope I just fixed it. |
81b3d6e to
3e8ab71
Compare
|
Sorry, changed it again because a similar functionality is needed in another PR. This is ready for review. |
| { | ||
| x = 3; // This should still assign to the outer variable | ||
| uint x; | ||
| x = 4; // This should assign to the new one |
There was a problem hiding this comment.
Perhaps another test could do a return x here.
There was a problem hiding this comment.
Added some more weird cases.
| pragma experimental "v0.5.0"; | ||
| contract test { | ||
| function f() public { | ||
| uint a = a; |
There was a problem hiding this comment.
Do we need a test for non-0.5.0 for this case? Perhaps it is covered somewhere.
| } | ||
| } | ||
| )"; | ||
| CHECK_WARNING(text, "Experimental features"); |
There was a problem hiding this comment.
Will need to rebase and fix this if #3600 is merged first.
| contract test { | ||
| function f() pure public { | ||
| for (uint x = 0; x < 10; x ++) | ||
| x = 2; |
There was a problem hiding this comment.
The only difference in this test compared to scoping_for is the lack of curly brackets. Is that intended?
There was a problem hiding this comment.
Yes, that is exactly the intention.
| char const* text = R"( | ||
| pragma experimental "v0.5.0"; | ||
| contract B { | ||
| function f() mod(x) pure public { uint x = 7; } |
There was a problem hiding this comment.
not sure, I can add a test.
docs/control-structures.rst
Outdated
|
|
||
| These rules are already introduced now as an experimental feature. | ||
|
|
||
| As a consequence, the following examples will compile without warnings (apart from |
There was a problem hiding this comment.
Maybe worth mentioning this is not compiling currently due to variable redeclaration.
There was a problem hiding this comment.
argh, weird, that should not happen.
There was a problem hiding this comment.
Ah sorry, I used the wrong solc version, everything is fine.
| @@ -90,6 +94,7 @@ class ReferencesResolver: private ASTConstVisitor | |||
| std::vector<ParameterList const*> m_returnParameters; | |||
| bool const m_resolveInsideCode; | |||
There was a problem hiding this comment.
What exactly is this setting?
There was a problem hiding this comment.
Reference resolution happens in two stages: In the first, all declarations at contract level are registered, but nothing inside code. In the second, code is also examined. This is necessary since at contract level, any declaration can appear anywhere, and for some parts - I don't remember anymore what exactly - it is important at this stage whether an identifier is a type name or e.g. a function, but only inside code.
| x = 7; | ||
| { | ||
| x = 3; | ||
| uint x = x; // This should read from the outer and assign to the inner |
There was a problem hiding this comment.
I take that as a compliment :)
It will generate a shadowing warning, so I think we do not need to make it more strict.
Fixes #1679 and #2495.
Still to do:
int a = ais impossible. (Self assignment at declaration (ambiguous construct) #2495){ a = 7; uint a;}is impossible.