mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
tmp
This commit is contained in:
parent
7a8c997438
commit
14a34ae088
@ -272,6 +272,12 @@ bool TypeInference::visit(Identifier const& _identifier)
|
||||
auto const* referencedDeclaration = _identifier.annotation().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);
|
||||
if (!declarationAnnotation.type)
|
||||
referencedDeclaration->accept(*this);
|
||||
@ -290,6 +296,11 @@ bool TypeInference::visit(IdentifierPath const& _identifier)
|
||||
|
||||
auto const* referencedDeclaration = _identifier.annotation().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);
|
||||
if (!declarationAnnotation.type)
|
||||
|
@ -176,22 +176,31 @@ void TypeSystem::validate(TypeVariable _variable) const
|
||||
|
||||
experimental::Type TypeSystem::fresh(Type _type, bool _generalize)
|
||||
{
|
||||
return std::visit(util::GenericVisitor{
|
||||
[&](TypeExpression const& _type) -> Type {
|
||||
return TypeExpression{
|
||||
_type.constructor,
|
||||
_type.arguments | ranges::view::transform([&](Type _argType) {
|
||||
return fresh(_argType, _generalize);
|
||||
}) | ranges::to<vector<Type>>
|
||||
};
|
||||
},
|
||||
[&](TypeVariable const& _var) {
|
||||
if (_generalize || _var.generic())
|
||||
return freshTypeVariable(true);
|
||||
else
|
||||
return _type;
|
||||
},
|
||||
}, resolve(_type));
|
||||
std::unordered_map<uint64_t, Type> mapping;
|
||||
auto freshImpl = [&](Type _type, bool _generalize, auto _recurse) -> Type {
|
||||
return std::visit(util::GenericVisitor{
|
||||
[&](TypeExpression const& _type) -> Type {
|
||||
return TypeExpression{
|
||||
_type.constructor,
|
||||
_type.arguments | ranges::view::transform([&](Type _argType) {
|
||||
return _recurse(_argType, _generalize, _recurse);
|
||||
}) | ranges::to<vector<Type>>
|
||||
};
|
||||
},
|
||||
[&](TypeVariable const& _var) -> Type {
|
||||
validate(_var);
|
||||
if (_generalize || _var.generic())
|
||||
{
|
||||
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
|
||||
|
@ -622,7 +622,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
|
||||
m_scanner->currentToken() == (m_experimentalSolidityEnabledInCurrentSourceUnit ? Token::RightArrow : Token::Returns)
|
||||
)
|
||||
{
|
||||
bool const permitEmptyParameterList = false;
|
||||
bool const permitEmptyParameterList = m_experimentalSolidityEnabledInCurrentSourceUnit;
|
||||
advance();
|
||||
result.returnParameters = parseParameterList(options, permitEmptyParameterList);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user