diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index dc3cfd087..593ca3654 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -570,6 +570,7 @@ bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract) m_globalContext.setCurrentContract(_contract); m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentThis(), nullptr, false, true); m_scopes[nullptr]->registerDeclaration(*m_globalContext.currentSuper(), nullptr, false, true); + m_currentContract = &_contract; registerDeclaration(_contract, true); _contract.annotation().canonicalName = currentCanonicalName(); @@ -578,6 +579,7 @@ bool DeclarationRegistrationHelper::visit(ContractDefinition& _contract) void DeclarationRegistrationHelper::endVisit(ContractDefinition&) { + m_currentContract = nullptr; closeCurrentScope(); } @@ -615,6 +617,7 @@ bool DeclarationRegistrationHelper::visit(FunctionDefinition& _function) { registerDeclaration(_function, true); m_currentFunction = &_function; + _function.annotation().contract = m_currentContract; return true; } diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 1f8d19419..56e640413 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -204,6 +204,7 @@ private: std::map>& m_scopes; ASTNode const* m_currentScope = nullptr; VariableScope* m_currentFunction = nullptr; + ContractDefinition const* m_currentContract = nullptr; langutil::ErrorReporter& m_errorReporter; GlobalContext& m_globalContext; }; diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h index c1eaed5f6..d1f70c828 100644 --- a/libsolidity/ast/ASTAnnotations.h +++ b/libsolidity/ast/ASTAnnotations.h @@ -109,6 +109,8 @@ struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation /// The function this function overrides, if any. This is always the closest /// in the linearized inheritance hierarchy. FunctionDefinition const* superFunction = nullptr; + /// Reference to the contract this function is defined in + ContractDefinition const* contract = nullptr; }; struct EventDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation