aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-14 00:39:31 +0800
committerGitHub <noreply@github.com>2018-04-14 00:39:31 +0800
commit95c49b367eaaec313b335d0953b5871dd445052c (patch)
tree150f88f057eaafed3d9a26f94b039b1bf7a4054b /libsolidity
parent2001cc6bdca87d715380b15f11c797666528e040 (diff)
parentbe37e3a912f6d5a2a57544f60362be65b7be8284 (diff)
downloaddexon-solidity-95c49b367eaaec313b335d0953b5871dd445052c.tar.gz
dexon-solidity-95c49b367eaaec313b335d0953b5871dd445052c.tar.zst
dexon-solidity-95c49b367eaaec313b335d0953b5871dd445052c.zip
Merge pull request #3875 from ethereum/constructorSelfRef
Stricter check for "this" in constructor.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index 51aa0b28..00a581d0 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -206,10 +206,32 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess)
);
}
- if (m_constructor && m_currentContract)
- if (ContractType const* type = dynamic_cast<ContractType const*>(_memberAccess.expression().annotation().type.get()))
- if (type->contractDefinition() == *m_currentContract)
- m_errorReporter.warning(_memberAccess.location(), "\"this\" used in constructor.");
+ if (m_constructor)
+ {
+ auto const* expr = &_memberAccess.expression();
+ while(expr)
+ {
+ if (auto id = dynamic_cast<Identifier const*>(expr))
+ {
+ if (id->name() == "this")
+ m_errorReporter.warning(
+ id->location(),
+ "\"this\" used in constructor. "
+ "Note that external functions of a contract "
+ "cannot be called while it is being constructed.");
+ break;
+ }
+ else if (auto tuple = dynamic_cast<TupleExpression const*>(expr))
+ {
+ if (tuple->components().size() == 1)
+ expr = tuple->components().front().get();
+ else
+ break;
+ }
+ else
+ break;
+ }
+ }
return true;
}