From 37e01a19c0c24f32ecdb978aa7c17db71fd5c769 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 8 Mar 2020 17:27:43 +0100 Subject: [PATCH] Fix scoping following try/catch. --- Changelog.md | 1 + libsolidity/analysis/ReferencesResolver.cpp | 16 ++++++++++++++++ libsolidity/analysis/ReferencesResolver.h | 2 ++ .../libsolidity/syntaxTests/tryCatch/scoping.sol | 10 ++++++++++ 4 files changed, 29 insertions(+) create mode 100644 test/libsolidity/syntaxTests/tryCatch/scoping.sol diff --git a/Changelog.md b/Changelog.md index a86b3ac59..92e31b9dc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Compiler Features: Bugfixes: * Inheritance: Fix incorrect error on calling unimplemented base functions. * isoltest: Added new keyword `wei` to express function value in semantic tests + * Reference Resolver: Fix scoping issue following try/catch statements. * Standard-JSON-Interface: Fix a bug related to empty filenames and imports. * SMTChecker: Fix internal errors when analysing tuples. * Yul AST Import: correctly import blocks as statements, switch statements and string literals. diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 4fe2d01c9..6867f049c 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -67,6 +67,22 @@ void ReferencesResolver::endVisit(Block const& _block) m_resolver.setScope(_block.scope()); } +bool ReferencesResolver::visit(TryCatchClause const& _tryCatchClause) +{ + if (!m_resolveInsideCode) + return false; + m_resolver.setScope(&_tryCatchClause); + return true; +} + +void ReferencesResolver::endVisit(TryCatchClause const& _tryCatchClause) +{ + if (!m_resolveInsideCode) + return; + + m_resolver.setScope(_tryCatchClause.scope()); +} + bool ReferencesResolver::visit(ForStatement const& _for) { if (!m_resolveInsideCode) diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index c560be31e..488562f21 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -70,6 +70,8 @@ private: bool visit(Block const& _block) override; void endVisit(Block const& _block) override; + bool visit(TryCatchClause const& _tryCatchClause) override; + void endVisit(TryCatchClause const& _tryCatchClause) override; bool visit(ForStatement const& _for) override; void endVisit(ForStatement const& _for) override; void endVisit(VariableDeclarationStatement const& _varDeclStatement) override; diff --git a/test/libsolidity/syntaxTests/tryCatch/scoping.sol b/test/libsolidity/syntaxTests/tryCatch/scoping.sol new file mode 100644 index 000000000..3c902c336 --- /dev/null +++ b/test/libsolidity/syntaxTests/tryCatch/scoping.sol @@ -0,0 +1,10 @@ +contract Test { + // This checks a scoping error, + // the variable "a" was not visible + // at the assignment. + function test(address _ext) external { + try Test(_ext).test(_ext) {} catch {} + uint a = 1; + a = 3; + } +}