aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-02-02 19:03:37 +0800
committerRhett Aultman <roadriverrail@gmail.com>2017-07-19 21:47:36 +0800
commitb3db1c361cc030aa76bec8184a59e05d192c2397 (patch)
tree1c2b6fad836f1f3ff54cdc9d3628fc0aa427d10c /libsolidity
parent84f8e7a46712f7da46ac15d378f0de0491278363 (diff)
downloaddexon-solidity-b3db1c361cc030aa76bec8184a59e05d192c2397.tar.gz
dexon-solidity-b3db1c361cc030aa76bec8184a59e05d192c2397.tar.zst
dexon-solidity-b3db1c361cc030aa76bec8184a59e05d192c2397.zip
Warn if this is used in constructor
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp9
-rw-r--r--libsolidity/analysis/StaticAnalyzer.h6
2 files changed, 15 insertions, 0 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index b1b31163..c81a46e7 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -38,12 +38,14 @@ bool StaticAnalyzer::analyze(SourceUnit const& _sourceUnit)
bool StaticAnalyzer::visit(ContractDefinition const& _contract)
{
m_library = _contract.isLibrary();
+ m_currentContract = &_contract;
return true;
}
void StaticAnalyzer::endVisit(ContractDefinition const&)
{
m_library = false;
+ m_currentContract = nullptr;
}
bool StaticAnalyzer::visit(FunctionDefinition const& _function)
@@ -54,6 +56,7 @@ bool StaticAnalyzer::visit(FunctionDefinition const& _function)
solAssert(!m_currentFunction, "");
solAssert(m_localVarUseCount.empty(), "");
m_nonPayablePublic = _function.isPublic() && !_function.isPayable();
+ m_constructor = _function.isConstructor();
return true;
}
@@ -61,6 +64,7 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&)
{
m_currentFunction = nullptr;
m_nonPayablePublic = false;
+ m_constructor = false;
for (auto const& var: m_localVarUseCount)
if (var.second == 0)
m_errorReporter.warning(var.first->location(), "Unused local variable");
@@ -131,6 +135,11 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess)
"\"callcode\" has been deprecated in favour of \"delegatecall\"."
);
+ if (m_constructor && m_currentContract)
+ if (ContractType const* type = dynamic_cast<ContractType const*>(_memberAccess.expression().annotation().type.get()))
+ if (type->contractDefinition() == *m_currentContract)
+ warning(_memberAccess.location(), "\"this\" used in constructor.");
+
return true;
}
diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h
index cd6913b5..21a487df 100644
--- a/libsolidity/analysis/StaticAnalyzer.h
+++ b/libsolidity/analysis/StaticAnalyzer.h
@@ -77,6 +77,12 @@ private:
std::map<VariableDeclaration const*, int> m_localVarUseCount;
FunctionDefinition const* m_currentFunction = nullptr;
+
+ /// Flag that indicates a constructor.
+ bool m_constructor = false;
+
+ /// Current contract.
+ ContractDefinition const* m_currentContract = nullptr;
};
}