Allow function overloads involving MagicVariableDeclarations.

This commit is contained in:
chriseth 2017-12-30 13:46:53 +01:00
parent 17fc0f54b5
commit f00bb43593
4 changed files with 18 additions and 7 deletions

View File

@ -45,7 +45,8 @@ Declaration const* DeclarationContainer::conflictingDeclaration(
if ( if (
dynamic_cast<FunctionDefinition const*>(&_declaration) || dynamic_cast<FunctionDefinition const*>(&_declaration) ||
dynamic_cast<EventDefinition const*>(&_declaration) dynamic_cast<EventDefinition const*>(&_declaration) ||
dynamic_cast<MagicVariableDeclaration const*>(&_declaration)
) )
{ {
// check that all other declarations with the same name are functions or a public state variable or events. // check that all other declarations with the same name are functions or a public state variable or events.
@ -68,6 +69,11 @@ Declaration const* DeclarationContainer::conflictingDeclaration(
!dynamic_cast<EventDefinition const*>(declaration) !dynamic_cast<EventDefinition const*>(declaration)
) )
return declaration; return declaration;
if (
dynamic_cast<MagicVariableDeclaration const*>(&_declaration) &&
!dynamic_cast<MagicVariableDeclaration const*>(declaration)
)
return declaration;
// Or, continue. // Or, continue.
} }
} }

View File

@ -202,8 +202,9 @@ vector<Declaration const*> NameAndTypeResolver::cleanedDeclarations(
solAssert( solAssert(
dynamic_cast<FunctionDefinition const*>(declaration) || dynamic_cast<FunctionDefinition const*>(declaration) ||
dynamic_cast<EventDefinition const*>(declaration) || dynamic_cast<EventDefinition const*>(declaration) ||
dynamic_cast<VariableDeclaration const*>(declaration), dynamic_cast<VariableDeclaration const*>(declaration) ||
"Found overloading involving something not a function or a variable." dynamic_cast<MagicVariableDeclaration const*>(declaration),
"Found overloading involving something not a function, event or a (magic) variable."
); );
FunctionTypePointer functionType { declaration->functionType(false) }; FunctionTypePointer functionType { declaration->functionType(false) };

View File

@ -2124,10 +2124,9 @@ bool TypeChecker::visit(Identifier const& _identifier)
for (Declaration const* declaration: annotation.overloadedDeclarations) for (Declaration const* declaration: annotation.overloadedDeclarations)
{ {
TypePointer function = declaration->type(); FunctionTypePointer functionType = declaration->functionType(true);
solAssert(!!function, "Requested type not present."); solAssert(!!functionType, "Requested type not present.");
auto const* functionType = dynamic_cast<FunctionType const*>(function.get()); if (functionType->canTakeArguments(*annotation.argumentTypes))
if (functionType && functionType->canTakeArguments(*annotation.argumentTypes))
candidates.push_back(declaration); candidates.push_back(declaration);
} }
if (candidates.empty()) if (candidates.empty())

View File

@ -831,6 +831,11 @@ public:
solAssert(false, "MagicVariableDeclaration used inside real AST."); solAssert(false, "MagicVariableDeclaration used inside real AST.");
} }
virtual FunctionTypePointer functionType(bool) const override
{
solAssert(m_type->category() == Type::Category::Function, "");
return std::dynamic_pointer_cast<FunctionType const>(m_type);
}
virtual TypePointer type() const override { return m_type; } virtual TypePointer type() const override { return m_type; }
private: private: