aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/DeclarationContainer.cpp11
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp57
-rw-r--r--libsolidity/analysis/TypeChecker.cpp47
3 files changed, 87 insertions, 28 deletions
diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp
index ac56562e..042b7a6a 100644
--- a/libsolidity/analysis/DeclarationContainer.cpp
+++ b/libsolidity/analysis/DeclarationContainer.cpp
@@ -49,6 +49,8 @@ Declaration const* DeclarationContainer::conflictingDeclaration(
if (!dynamic_cast<FunctionDefinition const*>(declaration))
return declaration;
}
+ else if (declarations.size() == 1 && declarations.front() == &_declaration)
+ return nullptr;
else if (!declarations.empty())
return declarations.front();
@@ -73,13 +75,12 @@ bool DeclarationContainer::registerDeclaration(
m_declarations.erase(*_name);
m_invisibleDeclarations.erase(*_name);
}
- else if (conflictingDeclaration(_declaration))
+ else if (conflictingDeclaration(_declaration, _name))
return false;
- if (_invisible)
- m_invisibleDeclarations[*_name].push_back(&_declaration);
- else
- m_declarations[*_name].push_back(&_declaration);
+ vector<Declaration const*>& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name];
+ if (!contains(decls, &_declaration))
+ decls.push_back(&_declaration);
return true;
}
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index 96ffdd6e..5e407383 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -76,23 +76,58 @@ bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map<string, So
string const& path = imp->annotation().absolutePath;
if (!_sourceUnits.count(path))
{
- reportDeclarationError( node->location(),
- "Import \"" +
- path +
- "\" (referenced as \"" +
- imp->path() +
- "\") not found."
+ reportDeclarationError(
+ imp->location(),
+ "Import \"" + path + "\" (referenced as \"" + imp->path() + "\") not found."
);
error = true;
+ continue;
}
+ auto scope = m_scopes.find(_sourceUnits.at(path));
+ solAssert(scope != end(m_scopes), "");
+ if (!imp->symbolAliases().empty())
+ for (auto const& alias: imp->symbolAliases())
+ {
+ auto declarations = scope->second->resolveName(alias.first->name(), false);
+ if (declarations.empty())
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Declaration \"" +
+ alias.first->name() +
+ "\" not found in \"" +
+ path +
+ "\" (referenced as \"" +
+ imp->path() +
+ "\")."
+ );
+ error = true;
+ }
+ else
+ for (Declaration const* declaration: declarations)
+ {
+ ASTString const* name = alias.second ? alias.second.get() : &declaration->name();
+ if (!target.registerDeclaration(*declaration, name))
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Identifier \"" + *name + "\" already declared."
+ );
+ error = true;
+ }
+ }
+ }
else if (imp->name().empty())
- {
- auto scope = m_scopes.find(_sourceUnits.at(path));
- solAssert(scope != end(m_scopes), "");
for (auto const& nameAndDeclaration: scope->second->declarations())
for (auto const& declaration: nameAndDeclaration.second)
- target.registerDeclaration(*declaration, &nameAndDeclaration.first);
- }
+ if (!target.registerDeclaration(*declaration, &nameAndDeclaration.first))
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Identifier \"" + nameAndDeclaration.first + "\" already declared."
+ );
+ error = true;
+ }
}
return !error;
}
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 669a7e4a..69357043 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -292,17 +292,21 @@ void TypeChecker::checkContractExternalTypeClashes(ContractDefinition const& _co
if (f->isPartOfExternalInterface())
{
auto functionType = make_shared<FunctionType>(*f);
- externalDeclarations[functionType->externalSignature()].push_back(
- make_pair(f, functionType)
- );
+ // under non error circumstances this should be true
+ if (functionType->interfaceFunctionType())
+ externalDeclarations[functionType->externalSignature()].push_back(
+ make_pair(f, functionType)
+ );
}
for (VariableDeclaration const* v: contract->stateVariables())
if (v->isPartOfExternalInterface())
{
auto functionType = make_shared<FunctionType>(*v);
- externalDeclarations[functionType->externalSignature()].push_back(
- make_pair(v, functionType)
- );
+ // under non error circumstances this should be true
+ if (functionType->interfaceFunctionType())
+ externalDeclarations[functionType->externalSignature()].push_back(
+ make_pair(v, functionType)
+ );
}
}
for (auto const& it: externalDeclarations)
@@ -783,10 +787,12 @@ bool TypeChecker::visit(Assignment const& _assignment)
bool TypeChecker::visit(TupleExpression const& _tuple)
{
vector<ASTPointer<Expression>> const& components = _tuple.components();
- solAssert(!_tuple.isInlineArray(), "Tuple type not properly declared");
TypePointers types;
+
if (_tuple.annotation().lValueRequested)
{
+ if (_tuple.isInlineArray())
+ fatalTypeError(_tuple.location(), "Inline array type cannot be declared as LValue.");
for (auto const& component: components)
if (component)
{
@@ -804,6 +810,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
}
else
{
+ TypePointer inlineArrayType;
for (size_t i = 0; i < components.size(); ++i)
{
// Outside of an lvalue-context, the only situation where a component can be empty is (x,).
@@ -813,18 +820,34 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
{
components[i]->accept(*this);
types.push_back(type(*components[i]));
+ if (_tuple.isInlineArray())
+ solAssert(!!types[i], "Inline array cannot have empty components");
+ if (i == 0 && _tuple.isInlineArray())
+ inlineArrayType = types[i]->mobileType();
+ else if (_tuple.isInlineArray() && inlineArrayType)
+ inlineArrayType = Type::commonType(inlineArrayType, types[i]->mobileType());
}
else
types.push_back(TypePointer());
}
- if (components.size() == 1)
- _tuple.annotation().type = type(*components[0]);
+ if (_tuple.isInlineArray())
+ {
+ if (!inlineArrayType)
+ fatalTypeError(_tuple.location(), "Unable to deduce common type for array elements.");
+ _tuple.annotation().type = make_shared<ArrayType>(DataLocation::Memory, inlineArrayType, types.size());
+ }
else
{
- if (components.size() == 2 && !components[1])
- types.pop_back();
- _tuple.annotation().type = make_shared<TupleType>(types);
+ if (components.size() == 1)
+ _tuple.annotation().type = type(*components[0]);
+ else
+ {
+ if (components.size() == 2 && !components[1])
+ types.pop_back();
+ _tuple.annotation().type = make_shared<TupleType>(types);
+ }
}
+
}
return false;
}