Skip to content

Commit 3078a9f

Browse files
authored
Merge pull request #14658 from ethereum/new-analysis-bugfixes
Assorted bugfixes for new analysis
2 parents 98008bd + 9ac8ba4 commit 3078a9f

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

Diff for: libsolidity/experimental/analysis/DebugWarner.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ bool DebugWarner::analyze(ASTNode const& _astRoot)
3939

4040
bool DebugWarner::visitNode(ASTNode const& _node)
4141
{
42-
auto const& typeInferenceAnnotation = m_analysis.annotation<TypeInference>(_node);
43-
if (typeInferenceAnnotation.type)
44-
{
45-
Type type = *typeInferenceAnnotation.type;
46-
Sort sort = m_analysis.typeSystem().env().sort(type);
47-
std::string sortString;
48-
if (sort.classes.size() != 1 || *sort.classes.begin() != m_analysis.typeSystem().primitiveClass(PrimitiveClass::Type))
49-
sortString = ":" + TypeSystemHelpers{m_analysis.typeSystem()}.sortToString(m_analysis.typeSystem().env().sort(type));
42+
std::optional<Type> const& inferredType = m_analysis.annotation<TypeInference>(_node).type;
43+
if (inferredType.has_value())
5044
m_errorReporter.info(
5145
4164_error,
5246
_node.location(),
53-
"Inferred type: " + TypeEnvironmentHelpers{m_analysis.typeSystem().env()}.typeToString(type) + sortString
47+
"Inferred type: " + TypeEnvironmentHelpers{m_analysis.typeSystem().env()}.typeToString(*inferredType)
5448
);
55-
}
5649
return true;
5750
}

Diff for: libsolidity/experimental/ast/TypeSystem.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ std::vector<TypeEnvironment::UnificationFailure> TypeEnvironment::unify(Type _a,
4949
std::visit(util::GenericVisitor{
5050
[&](TypeVariable _left, TypeVariable _right) {
5151
if (_left.index() == _right.index())
52-
{
53-
if (_left.sort() != _right.sort())
54-
unificationFailure();
55-
}
52+
solAssert(_left.sort() == _right.sort());
5653
else
5754
{
5855
if (_left.sort() <= _right.sort())
@@ -154,7 +151,7 @@ TypeSystem::TypeSystem()
154151
Sort typeSort{{classType}};
155152
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::TypeFunction).m_index).arities = {Arity{std::vector<Sort>{{typeSort},{typeSort}}, classType}};
156153
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector<Sort>{{typeSort, typeSort}}, classType}};
157-
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Function).m_index).arities = {Arity{std::vector<Sort>{{typeSort, typeSort}}, classType}};
154+
m_typeConstructors.at(m_primitiveTypeConstructors.at(PrimitiveType::Itself).m_index).arities = {Arity{std::vector<Sort>{{typeSort, typeSort}}, classType}};
158155
}
159156

160157
experimental::Type TypeSystem::freshVariable(Sort _sort)
@@ -171,9 +168,10 @@ experimental::Type TypeSystem::freshTypeVariable(Sort _sort)
171168

172169
std::vector<TypeEnvironment::UnificationFailure> TypeEnvironment::instantiate(TypeVariable _variable, Type _type)
173170
{
174-
for (auto typeVar: TypeEnvironmentHelpers{*this}.typeVars(_type))
175-
if (typeVar.index() == _variable.index())
176-
return {UnificationFailure{RecursiveUnification{_variable, _type}}};
171+
for (auto const& maybeTypeVar: TypeEnvironmentHelpers{*this}.typeVars(_type))
172+
if (auto const* typeVar = std::get_if<TypeVariable>(&maybeTypeVar))
173+
if (typeVar->index() == _variable.index())
174+
return {UnificationFailure{RecursiveUnification{_variable, _type}}};
177175
Sort typeSort = sort(_type);
178176
if (!(_variable.sort() <= typeSort))
179177
{
@@ -197,19 +195,19 @@ experimental::Type TypeEnvironment::resolve(Type _type) const
197195
experimental::Type TypeEnvironment::resolveRecursive(Type _type) const
198196
{
199197
return std::visit(util::GenericVisitor{
200-
[&](TypeConstant const& _type) -> Type {
198+
[&](TypeConstant const& _typeConstant) -> Type {
201199
return TypeConstant{
202-
_type.constructor,
203-
_type.arguments | ranges::views::transform([&](Type _argType) {
200+
_typeConstant.constructor,
201+
_typeConstant.arguments | ranges::views::transform([&](Type const& _argType) {
204202
return resolveRecursive(_argType);
205203
}) | ranges::to<std::vector<Type>>
206204
};
207205
},
208-
[&](TypeVariable const&) -> Type {
209-
return _type;
206+
[](TypeVariable const& _typeVar) -> Type {
207+
return _typeVar;
210208
},
211-
[&](std::monostate) -> Type {
212-
return _type;
209+
[](std::monostate _nothing) -> Type {
210+
return _nothing;
213211
}
214212
}, resolve(_type));
215213
}
@@ -306,7 +304,7 @@ experimental::Type TypeSystem::type(TypeConstructor _constructor, std::vector<Ty
306304

307305
experimental::Type TypeEnvironment::fresh(Type _type)
308306
{
309-
std::unordered_map<uint64_t, Type> mapping;
307+
std::unordered_map<size_t, Type> mapping;
310308
auto freshImpl = [&](Type _type, auto _recurse) -> Type {
311309
return std::visit(util::GenericVisitor{
312310
[&](TypeConstant const& _type) -> Type {

0 commit comments

Comments
 (0)