This commit is contained in:
Daniel Kirchner 2023-06-21 02:15:01 +02:00
parent 7a8c997438
commit 14a34ae088
3 changed files with 37 additions and 17 deletions

View File

@ -272,6 +272,12 @@ bool TypeInference::visit(Identifier const& _identifier)
auto const* referencedDeclaration = _identifier.annotation().referencedDeclaration; auto const* referencedDeclaration = _identifier.annotation().referencedDeclaration;
solAssert(referencedDeclaration); solAssert(referencedDeclaration);
if (
!dynamic_cast<FunctionDefinition const*>(referencedDeclaration) &&
!dynamic_cast<VariableDeclaration const*>(referencedDeclaration)
)
m_errorReporter.fatalTypeError(0000_error, referencedDeclaration->location(), "Attempt to type ídentifier referring to unexpected node.");
auto& declarationAnnotation = annotation(*referencedDeclaration); auto& declarationAnnotation = annotation(*referencedDeclaration);
if (!declarationAnnotation.type) if (!declarationAnnotation.type)
referencedDeclaration->accept(*this); referencedDeclaration->accept(*this);
@ -290,6 +296,11 @@ bool TypeInference::visit(IdentifierPath const& _identifier)
auto const* referencedDeclaration = _identifier.annotation().referencedDeclaration; auto const* referencedDeclaration = _identifier.annotation().referencedDeclaration;
solAssert(referencedDeclaration); solAssert(referencedDeclaration);
if (
!dynamic_cast<FunctionDefinition const*>(referencedDeclaration) &&
!dynamic_cast<VariableDeclaration const*>(referencedDeclaration)
)
m_errorReporter.fatalTypeError(0000_error, referencedDeclaration->location(), "Attempt to type ídentifier referring to unexpected node.");
auto& declarationAnnotation = annotation(*referencedDeclaration); auto& declarationAnnotation = annotation(*referencedDeclaration);
if (!declarationAnnotation.type) if (!declarationAnnotation.type)

View File

@ -176,22 +176,31 @@ void TypeSystem::validate(TypeVariable _variable) const
experimental::Type TypeSystem::fresh(Type _type, bool _generalize) experimental::Type TypeSystem::fresh(Type _type, bool _generalize)
{ {
return std::visit(util::GenericVisitor{ std::unordered_map<uint64_t, Type> mapping;
[&](TypeExpression const& _type) -> Type { auto freshImpl = [&](Type _type, bool _generalize, auto _recurse) -> Type {
return TypeExpression{ return std::visit(util::GenericVisitor{
_type.constructor, [&](TypeExpression const& _type) -> Type {
_type.arguments | ranges::view::transform([&](Type _argType) { return TypeExpression{
return fresh(_argType, _generalize); _type.constructor,
}) | ranges::to<vector<Type>> _type.arguments | ranges::view::transform([&](Type _argType) {
}; return _recurse(_argType, _generalize, _recurse);
}, }) | ranges::to<vector<Type>>
[&](TypeVariable const& _var) { };
if (_generalize || _var.generic()) },
return freshTypeVariable(true); [&](TypeVariable const& _var) -> Type {
else validate(_var);
return _type; if (_generalize || _var.generic())
}, {
}, resolve(_type)); if (mapping.count(_var.index()))
return mapping[_var.index()];
return mapping[_var.index()] = freshTypeVariable(true);
}
else
return _type;
},
}, resolve(_type));
};
return freshImpl(_type, _generalize, freshImpl);
} }
experimental::Type TypeSystemHelpers::tupleType(vector<Type> _elements) const experimental::Type TypeSystemHelpers::tupleType(vector<Type> _elements) const

View File

@ -622,7 +622,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
m_scanner->currentToken() == (m_experimentalSolidityEnabledInCurrentSourceUnit ? Token::RightArrow : Token::Returns) m_scanner->currentToken() == (m_experimentalSolidityEnabledInCurrentSourceUnit ? Token::RightArrow : Token::Returns)
) )
{ {
bool const permitEmptyParameterList = false; bool const permitEmptyParameterList = m_experimentalSolidityEnabledInCurrentSourceUnit;
advance(); advance();
result.returnParameters = parseParameterList(options, permitEmptyParameterList); result.returnParameters = parseParameterList(options, permitEmptyParameterList);
} }