diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-08 15:34:13 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-09 14:47:04 +0000 |
commit | 705b8b73aa694a8cc79c4459beca192145f97542 (patch) | |
tree | 1eb94ea91366656b483d7f958da5a7bb43f1dcad | |
parent | 5a11dd79fcbcfc8b3fcd41f809c7fa373d637e41 (diff) | |
download | gcc-705b8b73aa694a8cc79c4459beca192145f97542.zip gcc-705b8b73aa694a8cc79c4459beca192145f97542.tar.gz gcc-705b8b73aa694a8cc79c4459beca192145f97542.tar.bz2 |
There was a bug with LetStmts where we name resolved the identifier
pattern first before the init expression. This lead to a situation
where shadowing rules were broken.
Example:
let x = 1;
let x = x + 1;
In this example the code was referencing the 2nd LetStmt as the resolved
name for the Identifier reference.
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/compilable/shadow2.rs | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 87b3cf3..6d751e6 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -51,12 +51,12 @@ public: void visit (AST::LetStmt &stmt) { + if (stmt.has_init_expr ()) + ResolveExpr::go (stmt.get_init_expr ().get (), stmt.get_node_id ()); + PatternDeclaration::go (stmt.get_pattern ().get (), stmt.get_node_id ()); if (stmt.has_type ()) ResolveType::go (stmt.get_type ().get (), stmt.get_node_id ()); - - if (stmt.has_init_expr ()) - ResolveExpr::go (stmt.get_init_expr ().get (), stmt.get_node_id ()); } private: diff --git a/gcc/testsuite/rust.test/compilable/shadow2.rs b/gcc/testsuite/rust.test/compilable/shadow2.rs new file mode 100644 index 0000000..fbac8c0 --- /dev/null +++ b/gcc/testsuite/rust.test/compilable/shadow2.rs @@ -0,0 +1,4 @@ +fn main() { + let x = 1; + let x = x + 1; +} |