diff --git a/libsolidity/experimental/analysis/DebugWarner.cpp b/libsolidity/experimental/analysis/DebugWarner.cpp index f99bd486768c..2b5c23b9bed0 100644 --- a/libsolidity/experimental/analysis/DebugWarner.cpp +++ b/libsolidity/experimental/analysis/DebugWarner.cpp @@ -39,19 +39,12 @@ bool DebugWarner::analyze(ASTNode const& _astRoot) bool DebugWarner::visitNode(ASTNode const& _node) { - auto const& typeInferenceAnnotation = m_analysis.annotation(_node); - if (typeInferenceAnnotation.type) - { - Type type = *typeInferenceAnnotation.type; - Sort sort = m_analysis.typeSystem().env().sort(type); - std::string sortString; - if (sort.classes.size() != 1 || *sort.classes.begin() != m_analysis.typeSystem().primitiveClass(PrimitiveClass::Type)) - sortString = ":" + TypeSystemHelpers{m_analysis.typeSystem()}.sortToString(m_analysis.typeSystem().env().sort(type)); + std::optional const& inferredType = m_analysis.annotation(_node).type; + if (inferredType.has_value()) m_errorReporter.info( 4164_error, _node.location(), - "Inferred type: " + TypeEnvironmentHelpers{m_analysis.typeSystem().env()}.typeToString(type) + sortString + "Inferred type: " + TypeEnvironmentHelpers{m_analysis.typeSystem().env()}.typeToString(*inferredType) ); - } return true; } diff --git a/libsolidity/experimental/ast/TypeSystem.cpp b/libsolidity/experimental/ast/TypeSystem.cpp index 717ecd4fe087..c3806dbc5c71 100644 --- a/libsolidity/experimental/ast/TypeSystem.cpp +++ b/libsolidity/experimental/ast/TypeSystem.cpp @@ -49,10 +49,7 @@ std::vector TypeEnvironment::unify(Type _a, std::visit(util::GenericVisitor{ [&](TypeVariable _left, TypeVariable _right) { if (_left.index() == _right.index()) - { - if (_left.sort() != _right.sort()) - unificationFailure(); - } + solAssert(_left.sort() == _right.sort()); else { if (_left.sort() <= _right.sort()) @@ -154,7 +151,7 @@ TypeSystem::TypeSystem() Sort typeSort{{classType}}; m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{std::vector{{typeSort},{typeSort}}, classType}}; m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector{{typeSort, typeSort}}, classType}}; - m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector{{typeSort, typeSort}}, classType}}; + m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Itself).m_index).arities = {Arity{std::vector{{typeSort, typeSort}}, classType}}; } experimental::Type TypeSystem::freshVariable(Sort _sort) @@ -171,9 +168,10 @@ experimental::Type TypeSystem::freshTypeVariable(Sort _sort) std::vector TypeEnvironment::instantiate(TypeVariable _variable, Type _type) { - for (auto typeVar: TypeEnvironmentHelpers{*this}.typeVars(_type)) - if (typeVar.index() == _variable.index()) - return {UnificationFailure{RecursiveUnification{_variable, _type}}}; + for (auto const& maybeTypeVar: TypeEnvironmentHelpers{*this}.typeVars(_type)) + if (auto const* typeVar = std::get_if(&maybeTypeVar)) + if (typeVar->index() == _variable.index()) + return {UnificationFailure{RecursiveUnification{_variable, _type}}}; Sort typeSort = sort(_type); if (!(_variable.sort() <= typeSort)) { @@ -197,19 +195,19 @@ experimental::Type TypeEnvironment::resolve(Type _type) const experimental::Type TypeEnvironment::resolveRecursive(Type _type) const { return std::visit(util::GenericVisitor{ - [&](TypeConstant const& _type) -> Type { + [&](TypeConstant const& _typeConstant) -> Type { return TypeConstant{ - _type.constructor, - _type.arguments | ranges::views::transform([&](Type _argType) { + _typeConstant.constructor, + _typeConstant.arguments | ranges::views::transform([&](Type const& _argType) { return resolveRecursive(_argType); }) | ranges::to> }; }, - [&](TypeVariable const&) -> Type { - return _type; + [](TypeVariable const& _typeVar) -> Type { + return _typeVar; }, - [&](std::monostate) -> Type { - return _type; + [](std::monostate _nothing) -> Type { + return _nothing; } }, resolve(_type)); } @@ -306,7 +304,7 @@ experimental::Type TypeSystem::type(TypeConstructor _constructor, std::vector mapping; + std::unordered_map mapping; auto freshImpl = [&](Type _type, auto _recurse) -> Type { return std::visit(util::GenericVisitor{ [&](TypeConstant const& _type) -> Type {