@@ -146,14 +146,14 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition)
146
146
147
147
148
148
_functionDefinition.parameterList ().accept (*this );
149
- unify (argumentsType, typeAnnotation (_functionDefinition.parameterList ()), _functionDefinition.parameterList ().location ());
149
+ unify (argumentsType, type (_functionDefinition.parameterList ()), _functionDefinition.parameterList ().location ());
150
150
if (_functionDefinition.experimentalReturnExpression ())
151
151
{
152
152
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
153
153
_functionDefinition.experimentalReturnExpression ()->accept (*this );
154
154
unify (
155
155
returnType,
156
- typeAnnotation (*_functionDefinition.experimentalReturnExpression ()),
156
+ type (*_functionDefinition.experimentalReturnExpression ()),
157
157
_functionDefinition.experimentalReturnExpression ()->location ()
158
158
);
159
159
}
@@ -171,7 +171,7 @@ void TypeInference::endVisit(Return const& _return)
171
171
solAssert (m_currentFunctionType);
172
172
Type functionReturnType = std::get<1 >(TypeSystemHelpers{m_typeSystem}.destFunctionType (*m_currentFunctionType));
173
173
if (_return.expression ())
174
- unify (functionReturnType, typeAnnotation (*_return.expression ()), _return.location ());
174
+ unify (functionReturnType, type (*_return.expression ()), _return.location ());
175
175
else
176
176
unify (functionReturnType, m_unitType, _return.location ());
177
177
}
@@ -181,7 +181,7 @@ void TypeInference::endVisit(ParameterList const& _parameterList)
181
181
auto & listAnnotation = annotation (_parameterList);
182
182
solAssert (!listAnnotation.type );
183
183
listAnnotation.type = TypeSystemHelpers{m_typeSystem}.tupleType (
184
- _parameterList.parameters () | ranges::views::transform ([&](auto _arg) { return typeAnnotation (*_arg); }) | ranges::to<std::vector<Type>>
184
+ _parameterList.parameters () | ranges::views::transform ([&](auto _arg) { return type (*_arg); }) | ranges::to<std::vector<Type>>
185
185
);
186
186
}
187
187
@@ -211,7 +211,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
211
211
subNode->accept (*this );
212
212
auto const * functionDefinition = dynamic_cast <FunctionDefinition const *>(subNode.get ());
213
213
solAssert (functionDefinition);
214
- auto functionType = typeAnnotation (*functionDefinition);
214
+ auto functionType = type (*functionDefinition);
215
215
if (!functionTypes.emplace (functionDefinition->name (), functionType).second )
216
216
m_errorReporter.fatalTypeError (3195_error, functionDefinition->location (), " Function in type class declared multiple times." );
217
217
auto typeVars = TypeEnvironmentHelpers{*m_env}.typeVars (functionType);
@@ -235,7 +235,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
235
235
m_errorReporter.typeError (1807_error, _typeClassDefinition.location (), " Function " + functionName + " depends on invalid type variable." );
236
236
}
237
237
238
- unify (typeAnnotation (_typeClassDefinition.typeVariable ()), m_typeSystem.freshTypeVariable ({{typeClass}}), _typeClassDefinition.location ());
238
+ unify (type (_typeClassDefinition.typeVariable ()), m_typeSystem.freshTypeVariable ({{typeClass}}), _typeClassDefinition.location ());
239
239
for (auto instantiation: m_analysis.annotation <TypeRegistration>(_typeClassDefinition).instantiations | ranges::views::values)
240
240
// TODO: recursion-safety? Order of instantiation?
241
241
instantiation->accept (*this );
@@ -268,7 +268,7 @@ bool TypeInference::visit(InlineAssembly const& _inlineAssembly)
268
268
solAssert (!!declaration, " " );
269
269
solAssert (identifierInfo->suffix == " " , " " );
270
270
271
- unify (typeAnnotation (*declaration), m_wordType, originLocationOf (_identifier));
271
+ unify (type (*declaration), m_wordType, originLocationOf (_identifier));
272
272
identifierInfo->valueSize = 1 ;
273
273
return true ;
274
274
};
@@ -302,7 +302,7 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
302
302
_binaryOperation.leftExpression ().accept (*this );
303
303
_binaryOperation.rightExpression ().accept (*this );
304
304
305
- Type argTuple = helper.tupleType ({typeAnnotation (_binaryOperation.leftExpression ()), typeAnnotation (_binaryOperation.rightExpression ())});
305
+ Type argTuple = helper.tupleType ({type (_binaryOperation.leftExpression ()), type (_binaryOperation.rightExpression ())});
306
306
Type resultType = m_typeSystem.freshTypeVariable ({});
307
307
Type genericFunctionType = helper.functionType (argTuple, resultType);
308
308
unify (functionType, genericFunctionType, _binaryOperation.location ());
@@ -316,8 +316,8 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
316
316
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
317
317
_binaryOperation.rightExpression ().accept (*this );
318
318
}
319
- Type leftType = typeAnnotation (_binaryOperation.leftExpression ());
320
- unify (leftType, typeAnnotation (_binaryOperation.rightExpression ()), _binaryOperation.location ());
319
+ Type leftType = type (_binaryOperation.leftExpression ());
320
+ unify (leftType, type (_binaryOperation.rightExpression ()), _binaryOperation.location ());
321
321
operationAnnotation.type = leftType;
322
322
}
323
323
else
@@ -334,21 +334,21 @@ bool TypeInference::visit(BinaryOperation const& _binaryOperation)
334
334
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Sort};
335
335
_binaryOperation.rightExpression ().accept (*this );
336
336
}
337
- Type leftType = typeAnnotation (_binaryOperation.leftExpression ());
338
- unify (leftType, typeAnnotation (_binaryOperation.rightExpression ()), _binaryOperation.location ());
337
+ Type leftType = type (_binaryOperation.leftExpression ());
338
+ unify (leftType, type (_binaryOperation.rightExpression ()), _binaryOperation.location ());
339
339
operationAnnotation.type = leftType;
340
340
}
341
341
else if (_binaryOperation.getOperator () == Token::RightArrow)
342
342
{
343
343
_binaryOperation.leftExpression ().accept (*this );
344
344
_binaryOperation.rightExpression ().accept (*this );
345
- operationAnnotation.type = helper.functionType (typeAnnotation (_binaryOperation.leftExpression ()), typeAnnotation (_binaryOperation.rightExpression ()));
345
+ operationAnnotation.type = helper.functionType (type (_binaryOperation.leftExpression ()), type (_binaryOperation.rightExpression ()));
346
346
}
347
347
else if (_binaryOperation.getOperator () == Token::BitOr )
348
348
{
349
349
_binaryOperation.leftExpression ().accept (*this );
350
350
_binaryOperation.rightExpression ().accept (*this );
351
- operationAnnotation.type = helper.sumType ({typeAnnotation (_binaryOperation.leftExpression ()), typeAnnotation (_binaryOperation.rightExpression ())});
351
+ operationAnnotation.type = helper.sumType ({type (_binaryOperation.leftExpression ()), type (_binaryOperation.rightExpression ())});
352
352
}
353
353
else
354
354
{
@@ -372,9 +372,9 @@ void TypeInference::endVisit(VariableDeclarationStatement const& _variableDeclar
372
372
m_errorReporter.typeError (2655_error, _variableDeclarationStatement.location (), " Multi variable declaration not supported." );
373
373
return ;
374
374
}
375
- Type variableType = typeAnnotation (*_variableDeclarationStatement.declarations ().front ());
375
+ Type variableType = type (*_variableDeclarationStatement.declarations ().front ());
376
376
if (_variableDeclarationStatement.initialValue ())
377
- unify (variableType, typeAnnotation (*_variableDeclarationStatement.initialValue ()), _variableDeclarationStatement.location ());
377
+ unify (variableType, type (*_variableDeclarationStatement.initialValue ()), _variableDeclarationStatement.location ());
378
378
}
379
379
380
380
bool TypeInference::visit (VariableDeclaration const & _variableDeclaration)
@@ -390,7 +390,7 @@ bool TypeInference::visit(VariableDeclaration const& _variableDeclaration)
390
390
{
391
391
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
392
392
_variableDeclaration.typeExpression ()->accept (*this );
393
- variableAnnotation.type = typeAnnotation (*_variableDeclaration.typeExpression ());
393
+ variableAnnotation.type = type (*_variableDeclaration.typeExpression ());
394
394
return false ;
395
395
}
396
396
variableAnnotation.type = m_typeSystem.freshTypeVariable ({});
@@ -401,7 +401,7 @@ bool TypeInference::visit(VariableDeclaration const& _variableDeclaration)
401
401
{
402
402
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Sort};
403
403
_variableDeclaration.typeExpression ()->accept (*this );
404
- unify (*variableAnnotation.type , typeAnnotation (*_variableDeclaration.typeExpression ()), _variableDeclaration.typeExpression ()->location ());
404
+ unify (*variableAnnotation.type , type (*_variableDeclaration.typeExpression ()), _variableDeclaration.typeExpression ()->location ());
405
405
}
406
406
return false ;
407
407
case ExpressionContext::Sort:
@@ -424,7 +424,7 @@ void TypeInference::endVisit(IfStatement const& _ifStatement)
424
424
return ;
425
425
}
426
426
427
- unify (typeAnnotation (_ifStatement.condition ()), m_boolType, _ifStatement.condition ().location ());
427
+ unify (type (_ifStatement.condition ()), m_boolType, _ifStatement.condition ().location ());
428
428
429
429
ifAnnotation.type = m_unitType;
430
430
}
@@ -441,8 +441,8 @@ void TypeInference::endVisit(Assignment const& _assignment)
441
441
return ;
442
442
}
443
443
444
- Type leftType = typeAnnotation (_assignment.leftHandSide ());
445
- unify (leftType, typeAnnotation (_assignment.rightHandSide ()), _assignment.location ());
444
+ Type leftType = type (_assignment.leftHandSide ());
445
+ unify (leftType, type (_assignment.rightHandSide ()), _assignment.location ());
446
446
assignmentAnnotation.type = leftType;
447
447
}
448
448
@@ -676,7 +676,7 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
676
676
}
677
677
}
678
678
679
- Type type {TypeConstant{*typeConstructor, arguments}};
679
+ Type instanceType {TypeConstant{*typeConstructor, arguments}};
680
680
681
681
std::map<std::string, Type> functionTypes;
682
682
@@ -685,17 +685,17 @@ bool TypeInference::visit(TypeClassInstantiation const& _typeClassInstantiation)
685
685
auto const * functionDefinition = dynamic_cast <FunctionDefinition const *>(subNode.get ());
686
686
solAssert (functionDefinition);
687
687
subNode->accept (*this );
688
- if (!functionTypes.emplace (functionDefinition->name (), typeAnnotation (*functionDefinition)).second )
688
+ if (!functionTypes.emplace (functionDefinition->name (), type (*functionDefinition)).second )
689
689
m_errorReporter.typeError (3654_error, subNode->location (), " Duplicate definition of function " + functionDefinition->name () + " during type class instantiation." );
690
690
}
691
691
692
- if (auto error = m_typeSystem.instantiateClass (type , arity))
692
+ if (auto error = m_typeSystem.instantiateClass (instanceType , arity))
693
693
m_errorReporter.typeError (5094_error, _typeClassInstantiation.location (), *error);
694
694
695
695
auto const & classFunctions = annotation ().typeClassFunctions .at (*typeClass);
696
696
697
697
TypeEnvironment newEnv = m_env->clone ();
698
- if (!newEnv.unify (m_typeSystem.typeClassVariable (*typeClass), type ).empty ())
698
+ if (!newEnv.unify (m_typeSystem.typeClassVariable (*typeClass), instanceType ).empty ())
699
699
{
700
700
m_errorReporter.typeError (4686_error, _typeClassInstantiation.location (), " Unification of class and instance variable failed." );
701
701
return false ;
@@ -758,7 +758,7 @@ void TypeInference::endVisit(MemberAccess const& _memberAccess)
758
758
{
759
759
auto & memberAccessAnnotation = annotation (_memberAccess);
760
760
solAssert (!memberAccessAnnotation.type );
761
- Type expressionType = typeAnnotation (_memberAccess.expression ());
761
+ Type expressionType = type (_memberAccess.expression ());
762
762
memberAccessAnnotation.type = memberType (expressionType, _memberAccess.memberName (), _memberAccess.location ());
763
763
}
764
764
@@ -824,7 +824,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall)
824
824
auto & functionCallAnnotation = annotation (_functionCall);
825
825
solAssert (!functionCallAnnotation.type );
826
826
827
- Type functionType = typeAnnotation (_functionCall.expression ());
827
+ Type functionType = type (_functionCall.expression ());
828
828
829
829
TypeSystemHelpers helper{m_typeSystem};
830
830
std::vector<Type> argTypes;
@@ -834,7 +834,7 @@ void TypeInference::endVisit(FunctionCall const& _functionCall)
834
834
{
835
835
case ExpressionContext::Term:
836
836
case ExpressionContext::Type:
837
- argTypes.emplace_back (typeAnnotation (*arg));
837
+ argTypes.emplace_back (type (*arg));
838
838
break ;
839
839
case ExpressionContext::Sort:
840
840
m_errorReporter.typeError (9173_error, _functionCall.location (), " Function call in sort context." );
@@ -1171,7 +1171,7 @@ void TypeInference::unify(Type _a, Type _b, langutil::SourceLocation _location)
1171
1171
}
1172
1172
}
1173
1173
1174
- experimental::Type TypeInference::typeAnnotation (ASTNode const & _node) const
1174
+ experimental::Type TypeInference::type (ASTNode const & _node) const
1175
1175
{
1176
1176
auto result = annotation (_node).type ;
1177
1177
solAssert (result);
0 commit comments