aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-17 06:45:24 +0800
committerChristian <c@ethdev.com>2014-12-17 06:49:02 +0800
commit147e77b61fd202cbfd593270cc2639477ea7c61e (patch)
treee45799327589cddf7af99b92cb906da9b7c497ce
parent5b802b685e794832bf8834183bf6c9604e513bbf (diff)
downloaddexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar.gz
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar.bz2
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar.lz
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar.xz
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.tar.zst
dexon-solidity-147e77b61fd202cbfd593270cc2639477ea7c61e.zip
Fix: Resolve function types of all contracts before checking types inside functions.
-rw-r--r--CompilerStack.cpp9
-rw-r--r--NameAndTypeResolver.cpp13
-rw-r--r--NameAndTypeResolver.h2
3 files changed, 18 insertions, 6 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp
index 23f5fd68..1242c0ab 100644
--- a/CompilerStack.cpp
+++ b/CompilerStack.cpp
@@ -73,6 +73,15 @@ void CompilerStack::parse()
resolver.resolveNamesAndTypes(*contract);
m_contracts[contract->getName()].contract = contract;
}
+ for (Source const* source: m_sourceOrder)
+ for (ASTPointer<ASTNode> const& node: source->ast->getNodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ m_globalContext->setCurrentContract(*contract);
+ resolver.updateDeclaration(*m_globalContext->getCurrentThis());
+ resolver.checkTypeRequirements(*contract);
+ m_contracts[contract->getName()].contract = contract;
+ }
m_parseSuccessful = true;
}
diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp
index 2ad27680..80732615 100644
--- a/NameAndTypeResolver.cpp
+++ b/NameAndTypeResolver.cpp
@@ -49,8 +49,6 @@ void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
m_currentScope = &m_scopes[&_contract];
for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
ReferencesResolver resolver(*structDef, *this, nullptr);
- for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
- structDef->checkValidityOfMembers();
for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables())
ReferencesResolver resolver(*variable, *this, nullptr);
for (ASTPointer<FunctionDefinition> const& function: _contract.getDefinedFunctions())
@@ -59,13 +57,16 @@ void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
ReferencesResolver referencesResolver(*function, *this,
function->getReturnParameterList().get());
}
- // First, the parameter types of all functions need to be resolved before we can check
- // the types, since it is possible to call functions that are only defined later
- // in the source.
- _contract.checkTypeRequirements();
m_currentScope = &m_scopes[nullptr];
}
+void NameAndTypeResolver::checkTypeRequirements(ContractDefinition& _contract)
+{
+ for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
+ structDef->checkValidityOfMembers();
+ _contract.checkTypeRequirements();
+}
+
void NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
{
m_scopes[nullptr].registerDeclaration(_declaration, true);
diff --git a/NameAndTypeResolver.h b/NameAndTypeResolver.h
index 1ff9febf..23ac5fe7 100644
--- a/NameAndTypeResolver.h
+++ b/NameAndTypeResolver.h
@@ -46,6 +46,8 @@ public:
void registerDeclarations(SourceUnit& _sourceUnit);
/// Resolves all names and types referenced from the given contract.
void resolveNamesAndTypes(ContractDefinition& _contract);
+ /// Check all type requirements in the given contract.
+ void checkTypeRequirements(ContractDefinition& _contract);
/// Updates the given global declaration (used for "this"). Not to be used with declarations
/// that create their own scope.
void updateDeclaration(Declaration const& _declaration);