GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.5% 409 / 3 / 427
Functions: 92.3% 12 / 0 / 13
Branches: 53.7% 666 / 8 / 1248

src/typechecker/TypeCheckerValues.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "TypeChecker.h"
4
5 #include <SourceFile.h>
6 #include <ast/ASTNodes.h>
7 #include <ast/Attributes.h>
8 #include <global/GlobalResourceManager.h>
9 #include <model/GenericType.h>
10 #include <symboltablebuilder/Scope.h>
11 #include <symboltablebuilder/ScopeHandle.h>
12 #include <symboltablebuilder/SymbolTableBuilder.h>
13 #include <typechecker/Builtins.h>
14 #include <typechecker/FunctionManager.h>
15 #include <typechecker/MacroDefs.h>
16 #include <typechecker/TypeMatcher.h>
17
18 namespace spice::compiler {
19
20 61544 std::any TypeChecker::visitValue(ValueNode *node) {
21 // Function call
22
2/2
✓ Branch 2 → 3 taken 55179 times.
✓ Branch 2 → 4 taken 6365 times.
61544 if (node->fctCall)
23 55179 return visit(node->fctCall);
24
25 // Array initialization
26
2/2
✓ Branch 4 → 5 taken 326 times.
✓ Branch 4 → 6 taken 6039 times.
6365 if (node->arrayInitialization)
27 326 return visit(node->arrayInitialization);
28
29 // Struct instantiation
30
2/2
✓ Branch 6 → 7 taken 1311 times.
✓ Branch 6 → 8 taken 4728 times.
6039 if (node->structInstantiation)
31 1311 return visit(node->structInstantiation);
32
33 // Lambda function
34
2/2
✓ Branch 8 → 9 taken 22 times.
✓ Branch 8 → 10 taken 4706 times.
4728 if (node->lambdaFunc)
35 22 return visit(node->lambdaFunc);
36
37 // Lambda procedure
38
2/2
✓ Branch 10 → 11 taken 39 times.
✓ Branch 10 → 12 taken 4667 times.
4706 if (node->lambdaProc)
39 39 return visit(node->lambdaProc);
40
41 // Lambda expression
42
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 4666 times.
4667 if (node->lambdaExpr)
43 1 return visit(node->lambdaExpr);
44
45 // Typed nil
46
1/2
✓ Branch 14 → 15 taken 4666 times.
✗ Branch 14 → 41 not taken.
4666 if (node->isNil) {
47
2/4
✓ Branch 15 → 16 taken 4666 times.
✗ Branch 15 → 52 not taken.
✓ Branch 16 → 17 taken 4666 times.
✗ Branch 16 → 50 not taken.
4666 const auto nilType = std::any_cast<QualType>(visit(node->nilType));
48
2/8
✓ Branch 18 → 19 taken 4666 times.
✗ Branch 18 → 62 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 4666 times.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 53 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 53 not taken.
4666 HANDLE_UNRESOLVED_TYPE_ER(nilType)
49
2/4
✓ Branch 24 → 25 taken 4666 times.
✗ Branch 24 → 62 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 36 taken 4666 times.
4666 if (nilType.is(TY_DYN))
50 SOFT_ERROR_ER(node->nilType, UNEXPECTED_DYN_TYPE, "Nil must have an explicit type")
51
2/4
✓ Branch 36 → 37 taken 4666 times.
✗ Branch 36 → 61 not taken.
✓ Branch 37 → 38 taken 4666 times.
✗ Branch 37 → 61 not taken.
9332 return ExprResult{node->setEvaluatedSymbolType(nilType, manIdx)};
52 }
53
54 throw CompilerError(UNHANDLED_BRANCH, "Value fall-through"); // GCOV_EXCL_LINE
55 }
56
57 54128 std::any TypeChecker::visitConstant(ConstantNode *node) {
58 SuperType superType;
59
7/8
✓ Branch 2 → 3 taken 1623 times.
✓ Branch 2 → 4 taken 7694 times.
✓ Branch 2 → 5 taken 1117 times.
✓ Branch 2 → 6 taken 18154 times.
✓ Branch 2 → 7 taken 4416 times.
✓ Branch 2 → 8 taken 13580 times.
✓ Branch 2 → 9 taken 7544 times.
✗ Branch 2 → 10 not taken.
54128 switch (node->type) {
60 1623 case ConstantNode::PrimitiveValueType::TYPE_DOUBLE:
61 1623 superType = TY_DOUBLE;
62 1623 break;
63 7694 case ConstantNode::PrimitiveValueType::TYPE_INT:
64 7694 superType = TY_INT;
65 7694 break;
66 1117 case ConstantNode::PrimitiveValueType::TYPE_SHORT:
67 1117 superType = TY_SHORT;
68 1117 break;
69 18154 case ConstantNode::PrimitiveValueType::TYPE_LONG:
70 18154 superType = TY_LONG;
71 18154 break;
72 4416 case ConstantNode::PrimitiveValueType::TYPE_CHAR:
73 4416 superType = TY_CHAR;
74 4416 break;
75 13580 case ConstantNode::PrimitiveValueType::TYPE_STRING:
76 13580 superType = TY_STRING;
77 13580 break;
78 7544 case ConstantNode::PrimitiveValueType::TYPE_BOOL:
79 7544 superType = TY_BOOL;
80 7544 break;
81 default: // GCOV_EXCL_LINE
82 throw CompilerError(UNHANDLED_BRANCH, "Constant fall-through"); // GCOV_EXCL_LINE
83 }
84
3/6
✓ Branch 18 → 19 taken 54128 times.
✗ Branch 18 → 33 not taken.
✓ Branch 19 → 20 taken 54128 times.
✗ Branch 19 → 33 not taken.
✓ Branch 20 → 21 taken 54128 times.
✗ Branch 20 → 33 not taken.
108256 return ExprResult{node->setEvaluatedSymbolType(QualType(superType), manIdx)};
85 }
86
87 55179 std::any TypeChecker::visitFctCall(FctCallNode *node) {
88
1/2
✓ Branch 2 → 3 taken 55179 times.
✗ Branch 2 → 524 not taken.
55179 FctCallNode::FctCallData &data = node->data.at(manIdx);
89 55179 auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data;
90
91 // Retrieve arg types
92 55179 args.clear();
93
2/2
✓ Branch 4 → 5 taken 39449 times.
✓ Branch 4 → 36 taken 15730 times.
55179 if (node->hasArgs) {
94
1/2
✓ Branch 6 → 7 taken 39449 times.
✗ Branch 6 → 524 not taken.
39449 args.reserve(node->argLst->args.size());
95
2/2
✓ Branch 34 → 9 taken 63179 times.
✓ Branch 34 → 35 taken 39433 times.
142061 for (ExprNode *arg : node->argLst->args) {
96 // Visit argument
97
3/4
✓ Branch 11 → 12 taken 63178 times.
✓ Branch 11 → 411 taken 1 time.
✓ Branch 12 → 13 taken 63178 times.
✗ Branch 12 → 409 not taken.
63179 const auto argResult = std::any_cast<ExprResult>(visit(arg));
98
5/8
✓ Branch 14 → 15 taken 63178 times.
✗ Branch 14 → 414 not taken.
✓ Branch 15 → 16 taken 15 times.
✓ Branch 15 → 20 taken 63163 times.
✓ Branch 16 → 17 taken 15 times.
✗ Branch 16 → 412 not taken.
✓ Branch 17 → 18 taken 15 times.
✗ Branch 17 → 412 not taken.
63193 HANDLE_UNRESOLVED_TYPE_ER(argResult.type)
99
2/4
✓ Branch 20 → 21 taken 63163 times.
✗ Branch 20 → 414 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 63163 times.
63163 assert(!argResult.type.hasAnyGenericParts());
100 // Save arg type to arg types list
101
1/2
✓ Branch 24 → 25 taken 63163 times.
✗ Branch 24 → 413 not taken.
63163 args.emplace_back(argResult.type, argResult.isTemporary());
102 }
103 }
104
105 // Retrieve template types
106 55163 templateTypes.clear();
107
2/2
✓ Branch 37 → 38 taken 4437 times.
✓ Branch 37 → 81 taken 50726 times.
55163 if (node->hasTemplateTypes) {
108
2/2
✓ Branch 79 → 40 taken 5600 times.
✓ Branch 79 → 80 taken 4437 times.
14474 for (DataTypeNode *templateTypeNode : node->templateTypeLst->dataTypes) {
109
2/4
✓ Branch 42 → 43 taken 5600 times.
✗ Branch 42 → 418 not taken.
✓ Branch 43 → 44 taken 5600 times.
✗ Branch 43 → 416 not taken.
5600 auto templateType = std::any_cast<QualType>(visit(templateTypeNode));
110
2/4
✓ Branch 45 → 46 taken 5600 times.
✗ Branch 45 → 427 not taken.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 5600 times.
5600 assert(!templateType.is(TY_INVALID));
111
112 // Abort if the type is unresolved
113
2/4
✓ Branch 48 → 49 taken 5600 times.
✗ Branch 48 → 427 not taken.
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 56 taken 5600 times.
5600 if (templateType.is(TY_UNRESOLVED))
114 HANDLE_UNRESOLVED_TYPE_ER(templateType)
115
116 // Check if the given type is generic
117
2/4
✓ Branch 56 → 57 taken 5600 times.
✗ Branch 56 → 427 not taken.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 68 taken 5600 times.
5600 if (templateType.is(TY_GENERIC))
118 SOFT_ERROR_ER(templateTypeNode, EXPECTED_NON_GENERIC_TYPE, "You must specify a concrete type here")
119
120
1/2
✓ Branch 68 → 69 taken 5600 times.
✗ Branch 68 → 427 not taken.
5600 templateTypes.push_back(templateType);
121 }
122 }
123
124 // Check if this is a builtin call
125
2/2
✓ Branch 88 → 82 taken 825940 times.
✓ Branch 88 → 89 taken 49822 times.
875762 for (const auto &[builtinFctName, _] : BUILTIN_FUNCTIONS)
126
2/2
✓ Branch 84 → 85 taken 5341 times.
✓ Branch 84 → 87 taken 820599 times.
825940 if (node->fqFunctionName == builtinFctName)
127
1/2
✓ Branch 85 → 86 taken 5341 times.
✗ Branch 85 → 524 not taken.
5341 return visitBuiltinCall(node);
128
129 // Retrieve entry of the first fragment
130 49822 const std::string &firstFrag = node->functionNameFragments.front();
131
1/2
✓ Branch 90 → 91 taken 49822 times.
✗ Branch 90 → 524 not taken.
49822 SymbolTableEntry *firstFragEntry = currentScope->lookup(firstFrag);
132
2/2
✓ Branch 93 → 94 taken 34634 times.
✓ Branch 93 → 131 taken 15188 times.
49822 if (firstFragEntry) {
133 // Check if we have seen a 'this.' prefix, because the generator needs that
134
6/8
✓ Branch 94 → 95 taken 1 time.
✓ Branch 94 → 98 taken 34633 times.
✓ Branch 95 → 96 taken 1 time.
✗ Branch 95 → 439 not taken.
✓ Branch 96 → 97 taken 1 time.
✗ Branch 96 → 98 not taken.
✓ Branch 99 → 100 taken 1 time.
✓ Branch 99 → 109 taken 34633 times.
34634 if (firstFragEntry->scope->type == ScopeType::STRUCT && firstFrag != THIS_VARIABLE_NAME)
135
5/10
✓ Branch 100 → 101 taken 1 time.
✗ Branch 100 → 433 not taken.
✓ Branch 101 → 102 taken 1 time.
✗ Branch 101 → 431 not taken.
✓ Branch 102 → 103 taken 1 time.
✗ Branch 102 → 429 not taken.
✓ Branch 105 → 106 taken 1 time.
✗ Branch 105 → 435 not taken.
✓ Branch 106 → 107 taken 1 time.
✗ Branch 106 → 435 not taken.
2 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_VARIABLE,
136 "The symbol '" + firstFrag + "' could not be found. Missing 'this.' prefix?")
137
138 34633 firstFragEntry->used = true;
139 // Decide of which type the function call is
140
2/4
✓ Branch 109 → 110 taken 34633 times.
✗ Branch 109 → 439 not taken.
✓ Branch 110 → 111 taken 34633 times.
✗ Branch 110 → 439 not taken.
34633 const QualType &baseType = firstFragEntry->getQualType().getBase();
141
5/8
✓ Branch 111 → 112 taken 34633 times.
✗ Branch 111 → 439 not taken.
✓ Branch 112 → 113 taken 4 times.
✓ Branch 112 → 117 taken 34629 times.
✓ Branch 113 → 114 taken 4 times.
✗ Branch 113 → 436 not taken.
✓ Branch 114 → 115 taken 4 times.
✗ Branch 114 → 436 not taken.
34637 HANDLE_UNRESOLVED_TYPE_ER(baseType)
142
3/4
✓ Branch 117 → 118 taken 34629 times.
✗ Branch 117 → 437 not taken.
✓ Branch 118 → 119 taken 28312 times.
✓ Branch 118 → 122 taken 6317 times.
34629 if (baseType.isOneOf({TY_STRUCT, TY_INTERFACE})) {
143
2/2
✓ Branch 119 → 120 taken 3536 times.
✓ Branch 119 → 121 taken 24776 times.
28312 if (firstFragEntry->scope->type == ScopeType::GLOBAL)
144 3536 callType = FctCallNode::FctCallType::TYPE_CTOR;
145 else
146 24776 callType = FctCallNode::FctCallType::TYPE_METHOD;
147
7/8
✓ Branch 122 → 123 taken 6317 times.
✗ Branch 122 → 438 not taken.
✓ Branch 123 → 124 taken 6159 times.
✓ Branch 123 → 126 taken 158 times.
✓ Branch 124 → 125 taken 70 times.
✓ Branch 124 → 126 taken 6089 times.
✓ Branch 127 → 128 taken 70 times.
✓ Branch 127 → 129 taken 6247 times.
6317 } else if (baseType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && firstFragEntry->scope->type != ScopeType::GLOBAL) {
148 70 callType = FctCallNode::FctCallType::TYPE_FCT_PTR;
149 }
150 }
151
152 // Get struct name. Retrieve it from alias if required
153
1/2
✓ Branch 131 → 132 taken 49817 times.
✗ Branch 131 → 524 not taken.
49817 const auto &[structEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqFunctionName);
154
4/6
✓ Branch 134 → 135 taken 1 time.
✓ Branch 134 → 138 taken 49816 times.
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 524 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 524 not taken.
49817 const std::string &fqFunctionName = isAlias ? structEntry->getQualType().getSubType() : node->fqFunctionName;
155
156 // Get the concrete template types
157
2/2
✓ Branch 139 → 140 taken 1 time.
✓ Branch 139 → 159 taken 49816 times.
49817 if (isAlias) {
158 // Retrieve concrete template types from type alias
159
3/6
✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 524 not taken.
✓ Branch 141 → 142 taken 1 time.
✗ Branch 141 → 524 not taken.
✓ Branch 142 → 143 taken 1 time.
✗ Branch 142 → 524 not taken.
1 templateTypes = structEntry->getQualType().getTemplateTypes();
160 // Check if the aliased type specified template types and the struct instantiation does
161
3/6
✓ Branch 144 → 145 taken 1 time.
✗ Branch 144 → 147 not taken.
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 147 taken 1 time.
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 159 taken 1 time.
1 if (!templateTypes.empty() && node->hasTemplateTypes)
162 SOFT_ERROR_ER(node->templateTypeLst, ALIAS_WITH_TEMPLATE_LIST, "The aliased type already has a template list")
163 }
164
165 // Check if this is a method call or a normal function call
166
2/2
✓ Branch 160 → 161 taken 24776 times.
✓ Branch 160 → 175 taken 25041 times.
49817 if (data.isMethodCall()) {
167 // This is a method call
168
1/2
✓ Branch 161 → 162 taken 24776 times.
✗ Branch 161 → 524 not taken.
24776 thisType = firstFragEntry->getQualType();
169
2/4
✓ Branch 162 → 163 taken 24776 times.
✗ Branch 162 → 447 not taken.
✓ Branch 163 → 164 taken 24776 times.
✗ Branch 163 → 447 not taken.
24776 Scope *structBodyScope = thisType.getBase().getBodyScope();
170
1/2
✗ Branch 164 → 165 not taken.
✓ Branch 164 → 166 taken 24776 times.
24776 assert(structBodyScope != nullptr);
171
3/4
✓ Branch 166 → 167 taken 24776 times.
✗ Branch 166 → 524 not taken.
✓ Branch 167 → 168 taken 2 times.
✓ Branch 167 → 173 taken 24774 times.
24776 if (!visitMethodCall(node, structBodyScope)) // Check if soft errors occurred
172
3/6
✓ Branch 168 → 169 taken 2 times.
✗ Branch 168 → 448 not taken.
✓ Branch 169 → 170 taken 2 times.
✗ Branch 169 → 448 not taken.
✓ Branch 170 → 171 taken 2 times.
✗ Branch 170 → 448 not taken.
4 return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)};
173
1/2
✗ Branch 173 → 174 not taken.
✓ Branch 173 → 211 taken 24774 times.
24774 assert(calleeParentScope != nullptr);
174
2/2
✓ Branch 176 → 177 taken 70 times.
✓ Branch 176 → 190 taken 24971 times.
25041 } else if (data.isFctPtrCall()) {
175 // This is a function pointer call
176
2/4
✓ Branch 177 → 178 taken 70 times.
✗ Branch 177 → 453 not taken.
✓ Branch 178 → 179 taken 70 times.
✗ Branch 178 → 453 not taken.
70 const QualType &functionType = firstFragEntry->getQualType().getBase();
177
2/4
✓ Branch 179 → 180 taken 70 times.
✗ Branch 179 → 450 not taken.
✗ Branch 180 → 181 not taken.
✓ Branch 180 → 182 taken 70 times.
70 assert(functionType.isOneOf({TY_FUNCTION, TY_PROCEDURE}));
178
2/4
✓ Branch 182 → 183 taken 70 times.
✗ Branch 182 → 453 not taken.
✗ Branch 183 → 184 not taken.
✓ Branch 183 → 189 taken 70 times.
70 if (!visitFctPtrCall(node, functionType)) // Check if soft errors occurred
179 return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)};
180 } else {
181 // This is an ordinary function call
182
3/4
✓ Branch 191 → 192 taken 3571 times.
✓ Branch 191 → 195 taken 21400 times.
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 3571 times.
24971 assert(data.isOrdinaryCall() || data.isCtorCall());
183
5/6
✓ Branch 195 → 196 taken 24971 times.
✗ Branch 195 → 456 not taken.
✓ Branch 196 → 197 taken 24969 times.
✓ Branch 196 → 454 taken 2 times.
✓ Branch 198 → 199 taken 4 times.
✓ Branch 198 → 204 taken 24965 times.
24973 if (!visitOrdinaryFctCall(node, fqFunctionName)) // Check if soft errors occurred
184
3/6
✓ Branch 199 → 200 taken 4 times.
✗ Branch 199 → 457 not taken.
✓ Branch 200 → 201 taken 4 times.
✗ Branch 200 → 457 not taken.
✓ Branch 201 → 202 taken 4 times.
✗ Branch 201 → 457 not taken.
8 return ExprResult{node->setEvaluatedSymbolType(QualType(TY_UNRESOLVED), manIdx)};
185
1/2
✗ Branch 204 → 205 not taken.
✓ Branch 204 → 206 taken 24965 times.
24965 assert(calleeParentScope != nullptr);
186
187 // If the call is no ordinary call, it must be a constructor, which takes a struct as this type.
188
4/6
✓ Branch 207 → 208 taken 8151 times.
✓ Branch 207 → 211 taken 16814 times.
✓ Branch 208 → 209 taken 8151 times.
✗ Branch 208 → 524 not taken.
✗ Branch 209 → 210 not taken.
✓ Branch 209 → 211 taken 8151 times.
24965 assert(data.isOrdinaryCall() || data.thisType.is(TY_STRUCT));
189 }
190
191
2/2
✓ Branch 212 → 213 taken 49739 times.
✓ Branch 212 → 284 taken 70 times.
49809 if (!data.isFctPtrCall()) {
192 // Check if we were able to find a function
193
2/2
✓ Branch 213 → 214 taken 12 times.
✓ Branch 213 → 251 taken 49727 times.
49739 if (!callee) {
194 // Build error message
195
6/10
✓ Branch 215 → 216 taken 2 times.
✓ Branch 215 → 219 taken 10 times.
✓ Branch 218 → 221 taken 2 times.
✗ Branch 218 → 459 not taken.
✓ Branch 220 → 221 taken 10 times.
✗ Branch 220 → 459 not taken.
✓ Branch 221 → 222 taken 2 times.
✓ Branch 221 → 224 taken 10 times.
✗ Branch 459 → 460 not taken.
✗ Branch 459 → 462 not taken.
14 const std::string functionName = data.isCtorCall() ? CTOR_FUNCTION_NAME : node->functionNameFragments.back();
196 12 ParamList errArgTypes;
197
1/2
✓ Branch 225 → 226 taken 12 times.
✗ Branch 225 → 479 not taken.
12 errArgTypes.reserve(args.size());
198
5/8
✓ Branch 226 → 227 taken 12 times.
✗ Branch 226 → 465 not taken.
✓ Branch 227 → 228 taken 12 times.
✗ Branch 227 → 465 not taken.
✓ Branch 228 → 229 taken 12 times.
✗ Branch 228 → 465 not taken.
✓ Branch 234 → 230 taken 7 times.
✓ Branch 234 → 235 taken 12 times.
19 for (const auto &type : args | std::views::keys)
199
1/2
✓ Branch 231 → 232 taken 7 times.
✗ Branch 231 → 464 not taken.
7 errArgTypes.push_back({type, false});
200
2/4
✓ Branch 236 → 237 taken 12 times.
✗ Branch 236 → 466 not taken.
✓ Branch 237 → 238 taken 12 times.
✗ Branch 237 → 466 not taken.
12 const std::string signature = Function::getSignature(functionName, thisType, QualType(TY_DYN), errArgTypes, {}, false);
201 // Throw error
202
5/10
✓ Branch 239 → 240 taken 12 times.
✗ Branch 239 → 474 not taken.
✓ Branch 240 → 241 taken 12 times.
✗ Branch 240 → 472 not taken.
✓ Branch 241 → 242 taken 12 times.
✗ Branch 241 → 470 not taken.
✓ Branch 244 → 245 taken 12 times.
✗ Branch 244 → 476 not taken.
✓ Branch 245 → 246 taken 12 times.
✗ Branch 245 → 476 not taken.
12 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_FUNCTION, "Function/procedure '" + signature + "' could not be found")
203 12 }
204
205 // Check if we need to request a re-visit, because the function body was not type-checked yet
206
1/2
✓ Branch 251 → 252 taken 49727 times.
✗ Branch 251 → 524 not taken.
49727 requestRevisitIfRequired(callee);
207
208 // Get function entry from function object
209 49727 SymbolTableEntry *functionEntry = callee->entry;
210
211 // Check if the called function has sufficient visibility
212
1/2
✓ Branch 252 → 253 taken 49727 times.
✗ Branch 252 → 524 not taken.
49727 isImported = calleeParentScope->isImportedBy(rootScope);
213
8/10
✓ Branch 253 → 254 taken 19619 times.
✓ Branch 253 → 258 taken 30108 times.
✓ Branch 254 → 255 taken 19619 times.
✗ Branch 254 → 524 not taken.
✓ Branch 255 → 256 taken 19619 times.
✗ Branch 255 → 524 not taken.
✓ Branch 256 → 257 taken 1 time.
✓ Branch 256 → 258 taken 19618 times.
✓ Branch 259 → 260 taken 1 time.
✓ Branch 259 → 284 taken 49726 times.
49727 if (isImported && !functionEntry->getQualType().isPublic()) {
214
1/2
✓ Branch 260 → 261 taken 1 time.
✗ Branch 260 → 500 not taken.
1 const QualType functionEntryType = functionEntry->getQualType();
215
1/2
✓ Branch 261 → 262 taken 1 time.
✗ Branch 261 → 500 not taken.
1 const std::string signature = callee->getSignature();
216
2/4
✓ Branch 262 → 263 taken 1 time.
✗ Branch 262 → 498 not taken.
✓ Branch 263 → 264 taken 1 time.
✗ Branch 263 → 273 not taken.
1 if (functionEntryType.is(TY_FUNCTION))
217
5/10
✓ Branch 264 → 265 taken 1 time.
✗ Branch 264 → 488 not taken.
✓ Branch 265 → 266 taken 1 time.
✗ Branch 265 → 486 not taken.
✓ Branch 266 → 267 taken 1 time.
✗ Branch 266 → 484 not taken.
✓ Branch 269 → 270 taken 1 time.
✗ Branch 269 → 490 not taken.
✓ Branch 270 → 271 taken 1 time.
✗ Branch 270 → 490 not taken.
2 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Function '" + signature + "' has insufficient visibility")
218 else
219 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Procedure '" + signature + "' has insufficient visibility")
220 1 }
221 }
222
223 // Generate arg infos
224
2/2
✓ Branch 284 → 285 taken 35208 times.
✓ Branch 284 → 327 taken 14588 times.
49796 if (node->hasArgs) {
225 35208 QualTypeList paramTypes;
226
2/2
✓ Branch 286 → 287 taken 44 times.
✓ Branch 286 → 293 taken 35164 times.
35208 if (data.isFctPtrCall()) {
227
2/4
✓ Branch 287 → 288 taken 44 times.
✗ Branch 287 → 502 not taken.
✓ Branch 288 → 289 taken 44 times.
✗ Branch 288 → 502 not taken.
44 const QualType &functionType = firstFragEntry->getQualType().getBase();
228
1/2
✓ Branch 289 → 290 taken 44 times.
✗ Branch 289 → 501 not taken.
44 paramTypes = functionType.getFunctionParamTypes();
229 } else {
230
1/2
✗ Branch 293 → 294 not taken.
✓ Branch 293 → 295 taken 35164 times.
35164 assert(callee != nullptr);
231
1/2
✓ Branch 295 → 296 taken 35164 times.
✗ Branch 295 → 503 not taken.
35164 paramTypes = callee->getParamTypes();
232 }
233
234 35208 node->argLst->argInfos.clear();
235
2/2
✓ Branch 320 → 301 taken 57485 times.
✓ Branch 320 → 321 taken 35208 times.
92693 for (size_t argIdx = 0; argIdx < args.size(); argIdx++) {
236
1/2
✓ Branch 301 → 302 taken 57485 times.
✗ Branch 301 → 505 not taken.
57485 const QualType &expectedType = paramTypes.at(argIdx);
237
1/2
✓ Branch 302 → 303 taken 57485 times.
✗ Branch 302 → 505 not taken.
57485 const auto &[actualType, _] = args.at(argIdx);
238
239 57485 Function *copyCtor = nullptr;
240
11/14
✓ Branch 305 → 306 taken 57485 times.
✗ Branch 305 → 505 not taken.
✓ Branch 306 → 307 taken 971 times.
✓ Branch 306 → 312 taken 56514 times.
✓ Branch 307 → 308 taken 971 times.
✗ Branch 307 → 505 not taken.
✓ Branch 308 → 309 taken 967 times.
✓ Branch 308 → 312 taken 4 times.
✓ Branch 309 → 310 taken 967 times.
✗ Branch 309 → 505 not taken.
✓ Branch 310 → 311 taken 47 times.
✓ Branch 310 → 312 taken 920 times.
✓ Branch 313 → 314 taken 47 times.
✓ Branch 313 → 317 taken 57438 times.
57485 if (expectedType.is(TY_STRUCT) && actualType.is(TY_STRUCT) && !actualType.isTriviallyCopyable(node)) {
241
1/2
✓ Branch 314 → 315 taken 47 times.
✗ Branch 314 → 505 not taken.
47 copyCtor = matchCopyCtor(actualType, node);
242 // Insert anonymous symbol to track the dtor call of the copy
243
1/2
✓ Branch 315 → 316 taken 47 times.
✗ Branch 315 → 505 not taken.
47 ExprNode *argNode = node->argLst->args.at(argIdx);
244
1/2
✓ Branch 316 → 317 taken 47 times.
✗ Branch 316 → 505 not taken.
47 currentScope->symbolTable.insertAnonymous(actualType, argNode, SIZE_MAX);
245 }
246
247
1/2
✓ Branch 317 → 318 taken 57485 times.
✗ Branch 317 → 504 not taken.
57485 node->argLst->argInfos.push_back(ArgLstNode::ArgInfo{copyCtor});
248 }
249
1/2
✗ Branch 323 → 324 not taken.
✓ Branch 323 → 325 taken 35208 times.
35208 assert(node->argLst->argInfos.size() == node->argLst->args.size());
250 35208 }
251
252 // Retrieve return type
253
6/10
✓ Branch 328 → 329 taken 70 times.
✓ Branch 328 → 333 taken 49726 times.
✓ Branch 329 → 330 taken 70 times.
✗ Branch 329 → 508 not taken.
✓ Branch 330 → 331 taken 70 times.
✗ Branch 330 → 508 not taken.
✓ Branch 331 → 332 taken 70 times.
✗ Branch 331 → 508 not taken.
✓ Branch 333 → 334 taken 49726 times.
✗ Branch 333 → 508 not taken.
99522 const bool isFct = data.isFctPtrCall() ? firstFragEntry->getQualType().getBase().is(TY_FUNCTION) : callee->isFunction();
254 49796 QualType returnType;
255
2/2
✓ Branch 338 → 339 taken 70 times.
✓ Branch 338 → 346 taken 49726 times.
49796 if (data.isFctPtrCall()) {
256
6/10
✓ Branch 339 → 340 taken 25 times.
✓ Branch 339 → 344 taken 45 times.
✓ Branch 340 → 341 taken 25 times.
✗ Branch 340 → 509 not taken.
✓ Branch 341 → 342 taken 25 times.
✗ Branch 341 → 509 not taken.
✓ Branch 342 → 343 taken 25 times.
✗ Branch 342 → 509 not taken.
✓ Branch 344 → 345 taken 45 times.
✗ Branch 344 → 509 not taken.
70 returnType = isFct ? firstFragEntry->getQualType().getBase().getFunctionReturnType() : QualType(TY_BOOL);
257
2/2
✓ Branch 347 → 348 taken 8149 times.
✓ Branch 347 → 349 taken 41577 times.
49726 } else if (data.isCtorCall()) {
258 8149 returnType = thisType;
259
3/4
✓ Branch 349 → 350 taken 41577 times.
✗ Branch 349 → 524 not taken.
✓ Branch 352 → 353 taken 10732 times.
✓ Branch 352 → 355 taken 30845 times.
83154 } else if (callee->isProcedure()) {
260
1/2
✓ Branch 353 → 354 taken 10732 times.
✗ Branch 353 → 511 not taken.
10732 returnType = QualType(TY_DYN);
261 } else {
262 30845 returnType = callee->returnType;
263 }
264
265
1/2
✓ Branch 356 → 357 taken 49796 times.
✗ Branch 356 → 524 not taken.
49796 const QualType returnBaseType = returnType.getBase();
266
267 // Make sure this source file knows about the return type
268
3/4
✓ Branch 357 → 358 taken 49796 times.
✗ Branch 357 → 524 not taken.
✓ Branch 358 → 359 taken 15523 times.
✓ Branch 358 → 362 taken 34273 times.
49796 if (returnBaseType.is(TY_STRUCT))
269
2/4
✓ Branch 359 → 360 taken 15523 times.
✗ Branch 359 → 512 not taken.
✓ Branch 360 → 361 taken 15523 times.
✗ Branch 360 → 512 not taken.
15523 returnType = mapImportedScopeTypeToLocalType(returnBaseType.getBodyScope(), returnType);
270
271 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
272 49796 SymbolTableEntry *anonymousSymbol = nullptr;
273
8/10
✓ Branch 362 → 363 taken 49796 times.
✗ Branch 362 → 524 not taken.
✓ Branch 363 → 364 taken 11598 times.
✓ Branch 363 → 367 taken 38198 times.
✓ Branch 364 → 365 taken 11598 times.
✗ Branch 364 → 524 not taken.
✓ Branch 365 → 366 taken 7173 times.
✓ Branch 365 → 367 taken 4425 times.
✓ Branch 368 → 369 taken 7173 times.
✓ Branch 368 → 371 taken 42623 times.
49796 if (returnType.is(TY_STRUCT) && !returnType.isTriviallyDestructible(node))
274
1/2
✓ Branch 369 → 370 taken 7173 times.
✗ Branch 369 → 524 not taken.
7173 anonymousSymbol = currentScope->symbolTable.insertAnonymous(returnType, node);
275
276 // Remove public qualifier to not have public local variables
277 49796 returnType.getQualifiers().isPublic = false;
278
279 // Check if the return value gets discarded
280
7/8
✓ Branch 372 → 373 taken 30870 times.
✓ Branch 372 → 376 taken 18926 times.
✓ Branch 373 → 374 taken 30870 times.
✗ Branch 373 → 524 not taken.
✓ Branch 374 → 375 taken 1469 times.
✓ Branch 374 → 376 taken 29401 times.
✓ Branch 377 → 378 taken 1469 times.
✓ Branch 377 → 403 taken 48327 times.
49796 if (isFct && !node->hasReturnValueReceiver()) {
281 // Check if we want to ignore the discarded return value
282 1469 bool ignoreUnusedReturnValue = false;
283
2/2
✓ Branch 379 → 380 taken 1466 times.
✓ Branch 379 → 400 taken 3 times.
1469 if (!data.isFctPtrCall()) {
284
1/2
✗ Branch 380 → 381 not taken.
✓ Branch 380 → 382 taken 1466 times.
1466 assert(callee != nullptr);
285
1/2
✓ Branch 382 → 383 taken 1466 times.
✗ Branch 382 → 384 not taken.
1466 auto fctDef = dynamic_cast<const FctDefNode *>(callee->declNode);
286
12/18
✓ Branch 385 → 386 taken 1181 times.
✓ Branch 385 → 393 taken 285 times.
✓ Branch 386 → 387 taken 281 times.
✓ Branch 386 → 393 taken 900 times.
✓ Branch 389 → 390 taken 281 times.
✗ Branch 389 → 513 not taken.
✓ Branch 390 → 391 taken 281 times.
✗ Branch 390 → 513 not taken.
✓ Branch 391 → 392 taken 264 times.
✓ Branch 391 → 393 taken 17 times.
✓ Branch 394 → 395 taken 281 times.
✓ Branch 394 → 396 taken 1185 times.
✓ Branch 396 → 397 taken 281 times.
✓ Branch 396 → 399 taken 1185 times.
✗ Branch 513 → 514 not taken.
✗ Branch 513 → 515 not taken.
✗ Branch 517 → 518 not taken.
✗ Branch 517 → 520 not taken.
2028 ignoreUnusedReturnValue = fctDef && fctDef->attrs && fctDef->attrs->attrLst->hasAttr(ATTR_IGNORE_UNUSED_RETURN_VALUE);
287 }
288
289
2/2
✓ Branch 400 → 401 taken 1205 times.
✓ Branch 400 → 403 taken 264 times.
1469 if (!ignoreUnusedReturnValue)
290
1/2
✓ Branch 401 → 402 taken 1205 times.
✗ Branch 401 → 522 not taken.
1205 warnings.emplace_back(node->codeLoc, UNUSED_RETURN_VALUE, "The return value of the function call is unused");
291 }
292
293
2/4
✓ Branch 403 → 404 taken 49796 times.
✗ Branch 403 → 523 not taken.
✓ Branch 404 → 405 taken 49796 times.
✗ Branch 404 → 523 not taken.
99592 return ExprResult{node->setEvaluatedSymbolType(returnType, manIdx), anonymousSymbol};
294 }
295
296 24971 bool TypeChecker::visitOrdinaryFctCall(FctCallNode *node, std::string fqFunctionName) const {
297
1/2
✓ Branch 2 → 3 taken 24971 times.
✗ Branch 2 → 112 not taken.
24971 FctCallNode::FctCallData &data = node->data.at(manIdx);
298 24971 auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data;
299
300 // Check if this is a well-known ctor/fct call
301
2/2
✓ Branch 4 → 5 taken 24819 times.
✓ Branch 4 → 7 taken 152 times.
24971 if (node->functionNameFragments.size() == 1) {
302
1/2
✓ Branch 5 → 6 taken 24819 times.
✗ Branch 5 → 112 not taken.
24819 ensureLoadedRuntimeForTypeName(fqFunctionName);
303
1/2
✓ Branch 6 → 7 taken 24819 times.
✗ Branch 6 → 112 not taken.
24819 ensureLoadedRuntimeForFunctionName(fqFunctionName);
304 }
305
306 // Check if the type is generic (possible in case of ctor call)
307
1/2
✓ Branch 7 → 8 taken 24971 times.
✗ Branch 7 → 112 not taken.
24971 const QualType *genericType = rootScope->lookupGenericTypeStrict(fqFunctionName);
308
6/8
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 12 taken 24970 times.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 112 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 19 taken 24970 times.
24971 if (genericType && typeMapping.contains(fqFunctionName)) {
309
1/2
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 112 not taken.
1 const QualType &replacementType = typeMapping.at(fqFunctionName);
310
2/4
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 112 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 19 not taken.
1 if (replacementType.is(TY_STRUCT))
311
2/4
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 112 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 112 not taken.
1 fqFunctionName = replacementType.getSubType();
312 }
313
314 // Check if the exported name registry contains that function name
315
1/2
✓ Branch 19 → 20 taken 24971 times.
✗ Branch 19 → 112 not taken.
24971 const NameRegistryEntry *functionRegistryEntry = sourceFile->getNameRegistryEntry(fqFunctionName);
316
2/2
✓ Branch 20 → 21 taken 3 times.
✓ Branch 20 → 28 taken 24968 times.
24971 if (!functionRegistryEntry) {
317
2/4
✓ Branch 22 → 23 taken 3 times.
✗ Branch 22 → 92 not taken.
✓ Branch 23 → 24 taken 3 times.
✗ Branch 23 → 90 not taken.
3 const std::string msg = "Function/procedure/struct '" + node->functionNameFragments.back() + "' could not be found";
318
1/2
✓ Branch 25 → 26 taken 3 times.
✗ Branch 25 → 93 not taken.
3 SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, msg)
319 3 }
320 24968 const SymbolTableEntry *functionEntry = functionRegistryEntry->targetEntry;
321 24968 calleeParentScope = functionRegistryEntry->targetScope;
322
323 // Check if the target symbol is a struct -> this must be a constructor call
324
1/2
✓ Branch 29 → 30 taken 24968 times.
✗ Branch 29 → 112 not taken.
24968 std::string functionName = node->functionNameFragments.back();
325
7/10
✓ Branch 30 → 31 taken 24968 times.
✗ Branch 30 → 35 not taken.
✓ Branch 31 → 32 taken 24968 times.
✗ Branch 31 → 110 not taken.
✓ Branch 32 → 33 taken 24968 times.
✗ Branch 32 → 110 not taken.
✓ Branch 33 → 34 taken 8152 times.
✓ Branch 33 → 35 taken 16816 times.
✓ Branch 36 → 37 taken 8152 times.
✓ Branch 36 → 52 taken 16816 times.
24968 if (functionEntry != nullptr && functionEntry->getQualType().is(TY_STRUCT)) {
326 8152 callType = FctCallNode::FctCallType::TYPE_CTOR;
327
1/2
✓ Branch 37 → 38 taken 8152 times.
✗ Branch 37 → 110 not taken.
8152 functionName = CTOR_FUNCTION_NAME;
328
329 8152 const NameRegistryEntry *structRegistryEntry = functionRegistryEntry;
330 8152 const SymbolTableEntry *structEntry = functionEntry;
331
332 // Substantiate potentially generic this struct
333
2/4
✓ Branch 38 → 39 taken 8152 times.
✗ Branch 38 → 110 not taken.
✓ Branch 39 → 40 taken 8152 times.
✗ Branch 39 → 110 not taken.
8152 const Struct *thisStruct = structEntry->getQualType().getStruct(node, templateTypes);
334
2/2
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 49 taken 8151 times.
8152 if (!thisStruct) {
335
1/2
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 103 not taken.
1 const std::string signature = Struct::getSignature(structRegistryEntry->targetEntry->name, templateTypes);
336
2/4
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 98 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 96 not taken.
1 const std::string errorMsg = "Could not find struct candidate for struct '" + signature + "'. Do the template types match?";
337
1/2
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 99 not taken.
1 SOFT_ERROR_BOOL(node, UNKNOWN_DATATYPE, errorMsg)
338 1 }
339
340 // Set the 'this' type of the function to the struct type
341
2/4
✓ Branch 49 → 50 taken 8151 times.
✗ Branch 49 → 104 not taken.
✓ Branch 50 → 51 taken 8151 times.
✗ Branch 50 → 104 not taken.
8151 thisType = structEntry->getQualType().getWithBodyScope(thisStruct->scope);
342 8151 calleeParentScope = thisStruct->scope;
343 }
344
345 // Attach the concrete template types to the 'this' type
346
7/8
✓ Branch 52 → 53 taken 24967 times.
✗ Branch 52 → 110 not taken.
✓ Branch 53 → 54 taken 8151 times.
✓ Branch 53 → 57 taken 16816 times.
✓ Branch 55 → 56 taken 1588 times.
✓ Branch 55 → 57 taken 6563 times.
✓ Branch 58 → 59 taken 1588 times.
✓ Branch 58 → 61 taken 23379 times.
24967 if (!thisType.is(TY_DYN) && !templateTypes.empty())
347
1/2
✓ Branch 59 → 60 taken 1588 times.
✗ Branch 59 → 105 not taken.
1588 thisType = thisType.getWithTemplateTypes(templateTypes);
348
349 // Map local arg types to imported types
350
5/8
✓ Branch 61 → 62 taken 24967 times.
✗ Branch 61 → 107 not taken.
✓ Branch 62 → 63 taken 24967 times.
✗ Branch 62 → 107 not taken.
✓ Branch 63 → 64 taken 24967 times.
✗ Branch 63 → 107 not taken.
✓ Branch 69 → 65 taken 42337 times.
✓ Branch 69 → 70 taken 24967 times.
67304 for (QualType &argType : args | std::views::keys)
351
1/2
✓ Branch 66 → 67 taken 42337 times.
✗ Branch 66 → 106 not taken.
42337 argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType);
352
353 // Map local template types to imported types
354
2/2
✓ Branch 84 → 72 taken 3676 times.
✓ Branch 84 → 85 taken 24967 times.
53610 for (QualType &templateType : templateTypes)
355
1/2
✓ Branch 74 → 75 taken 3676 times.
✗ Branch 74 → 108 not taken.
3676 templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType);
356
357 // Retrieve function object
358 24967 Scope *matchScope = calleeParentScope;
359
2/2
✓ Branch 85 → 86 taken 24965 times.
✓ Branch 85 → 110 taken 2 times.
24967 callee = FunctionManager::match(matchScope, functionName, data.thisType, data.args, templateTypes, false, node);
360
361 24965 return true;
362 24968 }
363
364 70 bool TypeChecker::visitFctPtrCall(const FctCallNode *node, const QualType &functionType) const {
365
1/2
✓ Branch 2 → 3 taken 70 times.
✗ Branch 2 → 75 not taken.
70 const FctCallNode::FctCallData &data = node->data.at(manIdx);
366 70 const auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] =
367 data;
368
369 // Check if the given argument types match the type
370
1/2
✓ Branch 3 → 4 taken 70 times.
✗ Branch 3 → 75 not taken.
70 const QualTypeList expectedArgTypes = functionType.getFunctionParamTypes();
371
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 14 taken 70 times.
70 if (args.size() != expectedArgTypes.size())
372 SOFT_ERROR_BOOL(node, REFERENCED_UNDEFINED_FUNCTION, "Expected and actual number of arguments do not match")
373
374 // Create resolver function, that always returns a nullptr
375 70 TypeMatcher::ResolverFct resolverFct = [](const std::string &) { return nullptr; };
376
377
2/2
✓ Branch 41 → 16 taken 52 times.
✓ Branch 41 → 42 taken 70 times.
122 for (size_t i = 0; i < args.size(); i++) {
378
1/2
✓ Branch 16 → 17 taken 52 times.
✗ Branch 16 → 71 not taken.
52 const QualType &actualType = args.at(i).first;
379
1/2
✓ Branch 17 → 18 taken 52 times.
✗ Branch 17 → 71 not taken.
52 const QualType &expectedType = expectedArgTypes.at(i);
380
2/4
✓ Branch 19 → 20 taken 52 times.
✗ Branch 19 → 68 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 34 taken 52 times.
52 if (TypeMapping tm; !TypeMatcher::matchRequestedToCandidateType(expectedType, actualType, tm, resolverFct, false))
381
1/16
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 66 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 61 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 59 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 57 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 55 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 53 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 53 not taken.
✓ Branch 36 → 37 taken 52 times.
✗ Branch 36 → 39 not taken.
52 SOFT_ERROR_BOOL(node->argLst->args.at(i), REFERENCED_UNDEFINED_FUNCTION,
382 "Expected " + expectedType.getName(false) + " but got " + actualType.getName(false))
383 }
384 70 return true;
385 70 }
386
387 24776 bool TypeChecker::visitMethodCall(FctCallNode *node, Scope *structScope) const {
388 24776 FctCallNode::FctCallData &data = node->data.at(manIdx);
389 24776 auto &[callType, isImported, templateTypes, thisType, args, callee, calleeParentScope, compTimeVal, hasCompTimeVal] = data;
390
391 // Traverse through structs - the first fragment is already looked up and the last one is the method name
392
2/2
✓ Branch 40 → 4 taken 7249 times.
✓ Branch 40 → 41 taken 24774 times.
32023 for (size_t i = 1; i < node->functionNameFragments.size() - 1; i++) {
393 7249 const std::string &identifier = node->functionNameFragments.at(i);
394
395 // Retrieve field entry
396 7249 SymbolTableEntry *fieldEntry = structScope->lookupStrict(identifier);
397
2/2
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 23 taken 7248 times.
7249 if (!fieldEntry) {
398
1/2
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 89 not taken.
1 std::stringstream errorMsg;
399
1/2
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 87 not taken.
1 errorMsg << "The type '";
400
3/6
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 82 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 82 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 80 not taken.
1 errorMsg << thisType.getBase().getName(false, true);
401
3/6
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 87 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 87 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 87 not taken.
1 errorMsg << "' does not have a member with the name '" << identifier << "'";
402
2/4
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 86 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 84 not taken.
1 SOFT_ERROR_BOOL(node, ACCESS_TO_NON_EXISTING_MEMBER, errorMsg.str())
403 1 }
404
5/8
✓ Branch 23 → 24 taken 7248 times.
✗ Branch 23 → 91 not taken.
✓ Branch 24 → 25 taken 7248 times.
✗ Branch 24 → 91 not taken.
✓ Branch 25 → 26 taken 7248 times.
✗ Branch 25 → 90 not taken.
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 33 taken 7247 times.
7248 if (!fieldEntry->getQualType().getBase().isOneOf({TY_STRUCT, TY_INTERFACE}))
405
3/6
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 96 not taken.
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 94 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 92 not taken.
1 SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS,
406 "Cannot call a method on '" + identifier + "', since it is no struct or interface")
407 7247 fieldEntry->used = true;
408
409 // Get struct type and scope
410 7247 thisType = fieldEntry->getQualType();
411
2/4
✓ Branch 34 → 35 taken 7247 times.
✗ Branch 34 → 98 not taken.
✓ Branch 35 → 36 taken 7247 times.
✗ Branch 35 → 98 not taken.
7247 structScope = thisType.getBase().getBodyScope();
412
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 7247 times.
7247 assert(structScope != nullptr);
413 }
414
415
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 50 taken 24774 times.
24774 if (thisType.is(TY_INTERFACE))
416 SOFT_ERROR_BOOL(node, INVALID_MEMBER_ACCESS, "Cannot call a method on an interface")
417
418 // Map local arg types to imported types
419 24774 Scope *matchScope = calleeParentScope = structScope;
420
5/8
✓ Branch 50 → 51 taken 24774 times.
✗ Branch 50 → 106 not taken.
✓ Branch 51 → 52 taken 24774 times.
✗ Branch 51 → 106 not taken.
✓ Branch 52 → 53 taken 24774 times.
✗ Branch 52 → 106 not taken.
✓ Branch 58 → 54 taken 15105 times.
✓ Branch 58 → 59 taken 24774 times.
39879 for (QualType &argType : args | std::views::keys)
421
1/2
✓ Branch 55 → 56 taken 15105 times.
✗ Branch 55 → 105 not taken.
15105 argType = mapLocalTypeToImportedScopeType(calleeParentScope, argType);
422
423 // Map local template types to imported types
424
2/2
✓ Branch 73 → 61 taken 337 times.
✓ Branch 73 → 74 taken 24774 times.
49885 for (QualType &templateType : templateTypes)
425
1/2
✓ Branch 63 → 64 taken 337 times.
✗ Branch 63 → 107 not taken.
337 templateType = mapLocalTypeToImportedScopeType(calleeParentScope, templateType);
426
427 // 'this' type
428
1/2
✓ Branch 74 → 75 taken 24774 times.
✗ Branch 74 → 109 not taken.
24774 thisType = thisType.autoDeReference();
429
1/2
✓ Branch 75 → 76 taken 24774 times.
✗ Branch 75 → 110 not taken.
24774 thisType = mapLocalTypeToImportedScopeType(calleeParentScope, thisType);
430
431 // Retrieve function object
432 24774 const std::string &functionName = node->functionNameFragments.back();
433 24774 callee = FunctionManager::match(matchScope, functionName, thisType, args, templateTypes, false, node);
434
435 24774 return true;
436 }
437
438 326 std::any TypeChecker::visitArrayInitialization(ArrayInitializationNode *node) {
439
5/6
✓ Branch 2 → 3 taken 325 times.
✓ Branch 2 → 5 taken 1 time.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 325 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 18 taken 325 times.
326 if (!node->itemLst || node->itemLst->args.empty())
440
4/8
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 74 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 80 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 80 not taken.
4 SOFT_ERROR_ER(node, ARRAY_SIZE_INVALID, "Array initializers must at least contain one value");
441 325 node->actualSize = node->itemLst->args.size();
442
443
1/2
✓ Branch 19 → 20 taken 325 times.
✗ Branch 19 → 105 not taken.
325 QualType actualItemType(TY_DYN);
444 // Check if all values have the same type
445
2/2
✓ Branch 63 → 22 taken 1453 times.
✓ Branch 63 → 64 taken 324 times.
2102 for (ExprNode *arg : node->itemLst->args) {
446
2/4
✓ Branch 24 → 25 taken 1453 times.
✗ Branch 24 → 83 not taken.
✓ Branch 25 → 26 taken 1453 times.
✗ Branch 25 → 81 not taken.
1453 const QualType itemType = std::any_cast<ExprResult>(visit(arg)).type;
447
2/8
✓ Branch 27 → 28 taken 1453 times.
✗ Branch 27 → 102 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 33 taken 1453 times.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 85 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 85 not taken.
1453 HANDLE_UNRESOLVED_TYPE_ER(itemType)
448
3/4
✓ Branch 33 → 34 taken 1453 times.
✗ Branch 33 → 102 not taken.
✓ Branch 34 → 35 taken 325 times.
✓ Branch 34 → 36 taken 1128 times.
1453 if (actualItemType.is(TY_DYN)) // Perform type inference
449 325 actualItemType = itemType;
450
3/4
✓ Branch 36 → 37 taken 1128 times.
✗ Branch 36 → 102 not taken.
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 53 taken 1127 times.
1128 else if (itemType != actualItemType) // Check if types are matching
451
8/16
✓ Branch 38 → 39 taken 1 time.
✗ Branch 38 → 99 not taken.
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 94 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 92 not taken.
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 90 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 88 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 86 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 101 not taken.
✓ Branch 50 → 51 taken 1 time.
✗ Branch 50 → 101 not taken.
2 SOFT_ERROR_ER(arg, ARRAY_ITEM_TYPE_NOT_MATCHING,
452 "All provided values have to be of the same data type. You provided " + actualItemType.getName(false) +
453 " and " + itemType.getName(false))
454 }
455
2/4
✓ Branch 64 → 65 taken 324 times.
✗ Branch 64 → 105 not taken.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 324 times.
324 assert(!actualItemType.is(TY_DYN));
456
457
1/2
✓ Branch 67 → 68 taken 324 times.
✗ Branch 67 → 105 not taken.
324 const QualType arrayType = actualItemType.toArr(node, node->actualSize, true);
458
2/4
✓ Branch 68 → 69 taken 324 times.
✗ Branch 68 → 104 not taken.
✓ Branch 69 → 70 taken 324 times.
✗ Branch 69 → 104 not taken.
648 return ExprResult{node->setEvaluatedSymbolType(arrayType, manIdx)};
459 }
460
461 1311 std::any TypeChecker::visitStructInstantiation(StructInstantiationNode *node) {
462 // Retrieve struct name
463
1/2
✓ Branch 2 → 3 taken 1311 times.
✗ Branch 2 → 297 not taken.
1311 const auto [aliasedEntry, isAlias] = rootScope->symbolTable.lookupWithAliasResolution(node->fqStructName);
464
5/8
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 9 taken 1310 times.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 297 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 297 not taken.
✓ Branch 10 → 11 taken 1311 times.
✗ Branch 10 → 297 not taken.
1311 std::string structName = isAlias ? aliasedEntry->getQualType().getSubType() : node->fqStructName;
465
466 // Check if the struct type is generic
467
1/2
✓ Branch 11 → 12 taken 1311 times.
✗ Branch 11 → 295 not taken.
1311 const QualType *genericType = rootScope->lookupGenericTypeStrict(structName);
468
6/8
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 16 taken 1309 times.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 295 not taken.
✓ Branch 14 → 15 taken 2 times.
✗ Branch 14 → 16 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 23 taken 1309 times.
1311 if (genericType && typeMapping.contains(structName)) {
469
1/2
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 295 not taken.
2 const QualType &replacementType = typeMapping.at(structName);
470
2/4
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 295 not taken.
✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 23 not taken.
2 if (replacementType.is(TY_STRUCT))
471
2/4
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 295 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 295 not taken.
2 structName = replacementType.getSubType();
472 }
473
474 // Retrieve struct
475
1/2
✓ Branch 23 → 24 taken 1311 times.
✗ Branch 23 → 295 not taken.
1311 const NameRegistryEntry *registryEntry = sourceFile->getNameRegistryEntry(structName);
476
2/2
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 1310 times.
1311 if (!registryEntry)
477
5/10
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 224 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 222 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 220 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 226 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 226 not taken.
2 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT, "Cannot find struct '" + structName + "'")
478
2/4
✓ Branch 34 → 35 taken 1310 times.
✗ Branch 34 → 37 not taken.
✓ Branch 35 → 36 taken 1310 times.
✗ Branch 35 → 37 not taken.
1310 assert(registryEntry->targetEntry != nullptr && registryEntry->targetScope != nullptr);
479 1310 SymbolTableEntry *structEntry = registryEntry->targetEntry;
480
481 // Check visibility
482
9/12
✓ Branch 38 → 39 taken 1310 times.
✗ Branch 38 → 295 not taken.
✓ Branch 39 → 40 taken 1310 times.
✗ Branch 39 → 295 not taken.
✓ Branch 40 → 41 taken 97 times.
✓ Branch 40 → 44 taken 1213 times.
✓ Branch 41 → 42 taken 97 times.
✗ Branch 41 → 295 not taken.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 44 taken 96 times.
✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 55 taken 1309 times.
1310 if (!structEntry->getQualType().isPublic() && structEntry->scope->isImportedBy(currentScope))
483
5/10
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 231 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 229 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 227 not taken.
✓ Branch 51 → 52 taken 1 time.
✗ Branch 51 → 233 not taken.
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 233 not taken.
2 SOFT_ERROR_ER(node, INSUFFICIENT_VISIBILITY, "Struct '" + structName + "' has insufficient visibility")
484
485 // Get struct type
486
1/2
✓ Branch 55 → 56 taken 1309 times.
✗ Branch 55 → 295 not taken.
1309 QualType structType = structEntry->getQualType();
487
488 // Get the concrete template types
489 1309 QualTypeList concreteTemplateTypes;
490
2/2
✓ Branch 56 → 57 taken 1 time.
✓ Branch 56 → 76 taken 1308 times.
1309 if (isAlias) {
491 // Retrieve concrete template types from type alias
492
3/6
✓ Branch 57 → 58 taken 1 time.
✗ Branch 57 → 293 not taken.
✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 293 not taken.
✓ Branch 59 → 60 taken 1 time.
✗ Branch 59 → 293 not taken.
1 concreteTemplateTypes = aliasedEntry->getQualType().getTemplateTypes();
493 // Check if the aliased type specified template types and the struct instantiation does
494
3/6
✓ Branch 61 → 62 taken 1 time.
✗ Branch 61 → 64 not taken.
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 1 time.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 76 taken 1 time.
1 if (!concreteTemplateTypes.empty() && node->templateTypeLst)
495 SOFT_ERROR_ER(node->templateTypeLst, ALIAS_WITH_TEMPLATE_LIST, "The aliased type already has a template list")
496 }
497
498
2/2
✓ Branch 76 → 77 taken 31 times.
✓ Branch 76 → 117 taken 1278 times.
1309 if (node->templateTypeLst) {
499
1/2
✓ Branch 78 → 79 taken 31 times.
✗ Branch 78 → 293 not taken.
31 concreteTemplateTypes.reserve(node->templateTypeLst->dataTypes.size());
500
2/2
✓ Branch 115 → 81 taken 57 times.
✓ Branch 115 → 116 taken 31 times.
119 for (DataTypeNode *dataType : node->templateTypeLst->dataTypes) {
501
2/4
✓ Branch 83 → 84 taken 57 times.
✗ Branch 83 → 243 not taken.
✓ Branch 84 → 85 taken 57 times.
✗ Branch 84 → 241 not taken.
57 auto concreteType = std::any_cast<QualType>(visit(dataType));
502
2/8
✓ Branch 86 → 87 taken 57 times.
✗ Branch 86 → 252 not taken.
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 92 taken 57 times.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 244 not taken.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 244 not taken.
57 HANDLE_UNRESOLVED_TYPE_ER(concreteType)
503 // Check if generic type
504
2/4
✓ Branch 92 → 93 taken 57 times.
✗ Branch 92 → 252 not taken.
✗ Branch 93 → 94 not taken.
✓ Branch 93 → 104 taken 57 times.
57 if (concreteType.is(TY_GENERIC))
505 SOFT_ERROR_ER(dataType, EXPECTED_NON_GENERIC_TYPE, "Struct instantiations may only take concrete template types")
506
1/2
✓ Branch 104 → 105 taken 57 times.
✗ Branch 104 → 252 not taken.
57 concreteTemplateTypes.push_back(concreteType);
507 }
508 }
509
510 // Get the struct instance
511
2/4
✓ Branch 117 → 118 taken 1309 times.
✗ Branch 117 → 293 not taken.
✓ Branch 118 → 119 taken 1309 times.
✗ Branch 118 → 293 not taken.
1309 Struct *spiceStruct = node->instantiatedStructs.at(manIdx) = structType.getStructAndAdjustType(node, concreteTemplateTypes);
512
1/2
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 131 taken 1309 times.
1309 if (!spiceStruct)
513 SOFT_ERROR_ER(node, REFERENCED_UNDEFINED_STRUCT,
514 "Struct '" + Struct::getSignature(structName, concreteTemplateTypes) + "' could not be found")
515
516 // Struct instantiation for an inheriting struct is forbidden, because the vtable needs to be initialized and this is done in
517 // the ctor of the struct, which is never called in case of struct instantiation
518
2/2
✓ Branch 132 → 133 taken 1 time.
✓ Branch 132 → 143 taken 1308 times.
1309 if (!spiceStruct->interfaceTypes.empty())
519
4/8
✓ Branch 135 → 136 taken 1 time.
✗ Branch 135 → 266 not taken.
✓ Branch 136 → 137 taken 1 time.
✗ Branch 136 → 264 not taken.
✓ Branch 139 → 140 taken 1 time.
✗ Branch 139 → 270 not taken.
✓ Branch 140 → 141 taken 1 time.
✗ Branch 140 → 270 not taken.
4 SOFT_ERROR_ER(node, INVALID_STRUCT_INSTANTIATION, "Struct instantiations for inheriting structs are forbidden")
520
521 // Check if the number of fields matches
522
2/2
✓ Branch 143 → 144 taken 1283 times.
✓ Branch 143 → 194 taken 25 times.
1308 if (node->fieldLst) { // Check if any fields are passed. Empty braces are also allowed
523
2/2
✓ Branch 146 → 147 taken 1 time.
✓ Branch 146 → 157 taken 1282 times.
1283 if (spiceStruct->fieldTypes.size() != node->fieldLst->args.size())
524
4/8
✓ Branch 149 → 150 taken 1 time.
✗ Branch 149 → 273 not taken.
✓ Branch 150 → 151 taken 1 time.
✗ Branch 150 → 271 not taken.
✓ Branch 153 → 154 taken 1 time.
✗ Branch 153 → 277 not taken.
✓ Branch 154 → 155 taken 1 time.
✗ Branch 154 → 277 not taken.
4 SOFT_ERROR_ER(node->fieldLst, NUMBER_OF_FIELDS_NOT_MATCHING,
525 "You've passed too less/many field values. Pass either none or all of them")
526
527 // Check if the field types are matching
528 1282 const size_t fieldCount = spiceStruct->fieldTypes.size();
529
1/2
✓ Branch 158 → 159 taken 1282 times.
✗ Branch 158 → 293 not taken.
1282 const size_t explicitFieldsStartIdx = spiceStruct->scope->getFieldCount() - fieldCount;
530
2/2
✓ Branch 193 → 160 taken 1734 times.
✓ Branch 193 → 206 taken 1281 times.
3015 for (size_t i = 0; i < node->fieldLst->args.size(); i++) {
531 // Get actual type
532
1/2
✓ Branch 160 → 161 taken 1734 times.
✗ Branch 160 → 284 not taken.
1734 ExprNode *assignExpr = node->fieldLst->args.at(i);
533
2/4
✓ Branch 161 → 162 taken 1734 times.
✗ Branch 161 → 280 not taken.
✓ Branch 162 → 163 taken 1734 times.
✗ Branch 162 → 278 not taken.
1734 auto fieldResult = std::any_cast<ExprResult>(visit(assignExpr));
534
2/8
✓ Branch 164 → 165 taken 1734 times.
✗ Branch 164 → 284 not taken.
✗ Branch 165 → 166 not taken.
✓ Branch 165 → 170 taken 1734 times.
✗ Branch 166 → 167 not taken.
✗ Branch 166 → 281 not taken.
✗ Branch 167 → 168 not taken.
✗ Branch 167 → 281 not taken.
1734 HANDLE_UNRESOLVED_TYPE_ER(fieldResult.type)
535 // Get expected type
536
1/2
✗ Branch 170 → 171 not taken.
✓ Branch 170 → 172 taken 1734 times.
1734 SymbolTableEntry *expectedField = spiceStruct->scope->lookupField(explicitFieldsStartIdx + i);
537
1/2
✗ Branch 175 → 176 not taken.
✓ Branch 175 → 177 taken 1734 times.
1734 assert(expectedField != nullptr);
538
1/2
✓ Branch 177 → 178 taken 1734 times.
✗ Branch 177 → 284 not taken.
1734 const ExprResult expected = {expectedField->getQualType(), expectedField};
539
1/2
✓ Branch 178 → 179 taken 1734 times.
✗ Branch 178 → 284 not taken.
1734 const bool rhsIsImmediate = assignExpr->hasCompileTimeValue(manIdx);
540
541 // Capture anonymous info up front: getFieldAssignResultType may delete the anonymous entry (temp stealing
542 // in performStructAssign), turning fieldResult.entry into a dangling pointer.
543
4/4
✓ Branch 179 → 180 taken 385 times.
✓ Branch 179 → 182 taken 1349 times.
✓ Branch 180 → 181 taken 7 times.
✓ Branch 180 → 182 taken 378 times.
1734 const bool rhsIsAnonymous = fieldResult.entry != nullptr && fieldResult.entry->anonymous;
544
3/4
✓ Branch 183 → 184 taken 7 times.
✓ Branch 183 → 185 taken 1727 times.
✓ Branch 184 → 186 taken 7 times.
✗ Branch 184 → 284 not taken.
1734 const std::string rhsEntryName = rhsIsAnonymous ? fieldResult.entry->name : std::string();
545
546 // Check if actual type matches expected type
547
2/2
✓ Branch 186 → 187 taken 1733 times.
✓ Branch 186 → 282 taken 1 time.
1734 (void)opRuleManager.getFieldAssignResultType(assignExpr, expected, fieldResult, rhsIsImmediate, true);
548
549 // If there is an anonymous entry attached (e.g. for struct instantiation), delete it.
550 // Safe to call even if performStructAssign already deleted it: map::erase by key is a no-op when absent.
551
2/2
✓ Branch 187 → 188 taken 7 times.
✓ Branch 187 → 190 taken 1726 times.
1733 if (rhsIsAnonymous) {
552
1/2
✓ Branch 188 → 189 taken 7 times.
✗ Branch 188 → 282 not taken.
7 currentScope->symbolTable.deleteAnonymous(rhsEntryName);
553 7 fieldResult.entry = nullptr;
554 }
555 1734 }
556 } else {
557
2/4
✓ Branch 194 → 195 taken 25 times.
✗ Branch 194 → 293 not taken.
✗ Branch 195 → 196 not taken.
✓ Branch 195 → 206 taken 25 times.
97 if (std::ranges::any_of(spiceStruct->fieldTypes, [](const QualType &fieldType) { return fieldType.isRef(); }))
558 SOFT_ERROR_ER(node, REFERENCE_WITHOUT_INITIALIZER,
559 "The struct takes at least one reference field. You need to instantiate it with all fields.")
560 }
561
562 // Update type of struct entry
563
1/2
✓ Branch 206 → 207 taken 1306 times.
✗ Branch 206 → 293 not taken.
1306 structEntry->updateType(structType, true);
564
565 // Add anonymous symbol to keep track of dtor call, if non-trivially destructible
566 1306 SymbolTableEntry *anonymousEntry = nullptr;
567
3/4
✓ Branch 207 → 208 taken 1306 times.
✗ Branch 207 → 293 not taken.
✓ Branch 208 → 209 taken 97 times.
✓ Branch 208 → 211 taken 1209 times.
1306 if (!structType.isTriviallyDestructible(node))
568
1/2
✓ Branch 209 → 210 taken 97 times.
✗ Branch 209 → 293 not taken.
97 anonymousEntry = currentScope->symbolTable.insertAnonymous(structType, node);
569
570 // Remove public qualifier to not have public local variables
571 1306 structType.getQualifiers().isPublic = false;
572
573
2/4
✓ Branch 212 → 213 taken 1306 times.
✗ Branch 212 → 292 not taken.
✓ Branch 213 → 214 taken 1306 times.
✗ Branch 213 → 292 not taken.
2612 return ExprResult{node->setEvaluatedSymbolType(structType, manIdx), anonymousEntry};
574 1312 }
575
576 22 std::any TypeChecker::visitLambdaFunc(LambdaFuncNode *node) {
577 // Check if all control paths in the lambda body return
578 22 bool returnsOnAllControlPaths = true;
579
3/4
✓ Branch 2 → 3 taken 22 times.
✗ Branch 2 → 194 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 14 taken 21 times.
22 if (!node->returnsOnAllControlPaths(&returnsOnAllControlPaths, manIdx))
580
4/8
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 120 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 118 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 124 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 124 not taken.
4 SOFT_ERROR_ER(node, MISSING_RETURN_STMT, "Not all control paths of this lambda function have a return statement")
581
582 // Change to function scope
583
2/4
✓ Branch 14 → 15 taken 21 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 21 times.
✗ Branch 15 → 125 not taken.
21 Scope *bodyScope = currentScope->getChildScope(node->getScopeId());
584
1/2
✓ Branch 17 → 18 taken 21 times.
✗ Branch 17 → 128 not taken.
21 ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY);
585
586 // Visit return type
587
2/4
✓ Branch 18 → 19 taken 21 times.
✗ Branch 18 → 131 not taken.
✓ Branch 19 → 20 taken 21 times.
✗ Branch 19 → 129 not taken.
21 const auto returnType = std::any_cast<QualType>(visit(node->returnType));
588
2/8
✓ Branch 21 → 22 taken 21 times.
✗ Branch 21 → 192 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 27 taken 21 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 132 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 132 not taken.
21 HANDLE_UNRESOLVED_TYPE_ER(returnType)
589
3/4
✓ Branch 27 → 28 taken 21 times.
✗ Branch 27 → 192 not taken.
✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 39 taken 20 times.
21 if (returnType.is(TY_DYN))
590
4/8
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 135 not taken.
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 133 not taken.
✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 139 not taken.
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 139 not taken.
4 SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed")
591
592 // Set the type of the result variable
593
1/2
✓ Branch 41 → 42 taken 20 times.
✗ Branch 41 → 142 not taken.
60 SymbolTableEntry *resultVarEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME);
594
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 20 times.
20 assert(resultVarEntry != nullptr);
595
1/2
✓ Branch 49 → 50 taken 20 times.
✗ Branch 49 → 192 not taken.
20 resultVarEntry->updateType(returnType, true);
596 20 resultVarEntry->used = true;
597
598 // Visit parameters
599 20 QualTypeList paramTypes;
600 20 ParamList paramList;
601
2/2
✓ Branch 50 → 51 taken 15 times.
✓ Branch 50 → 80 taken 5 times.
20 if (node->hasParams) {
602 // Visit param list to retrieve the param names
603
2/4
✓ Branch 51 → 52 taken 15 times.
✗ Branch 51 → 148 not taken.
✓ Branch 52 → 53 taken 15 times.
✗ Branch 52 → 146 not taken.
15 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
604
2/2
✓ Branch 77 → 56 taken 23 times.
✓ Branch 77 → 78 taken 15 times.
53 for (const auto &[name, qualType, isOptional] : namedParamList) {
605
1/2
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 66 taken 23 times.
23 if (isOptional)
606 softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters");
607
608
1/2
✓ Branch 66 → 67 taken 23 times.
✗ Branch 66 → 156 not taken.
23 paramTypes.push_back(qualType);
609
1/2
✓ Branch 67 → 68 taken 23 times.
✗ Branch 67 → 155 not taken.
23 paramList.push_back({qualType, isOptional});
610 }
611 15 }
612
613 // Visit lambda body
614
2/2
✓ Branch 80 → 81 taken 19 times.
✓ Branch 80 → 160 taken 1 time.
20 visit(node->body);
615
616 // Leave function body scope
617
1/2
✓ Branch 82 → 83 taken 19 times.
✗ Branch 82 → 188 not taken.
19 scopeHandle.leaveScopeEarly();
618
619 // Prepare type of function
620
1/2
✓ Branch 83 → 84 taken 19 times.
✗ Branch 83 → 161 not taken.
19 const QualType functionType = QualType(TY_FUNCTION)
621
1/2
✓ Branch 84 → 85 taken 19 times.
✗ Branch 84 → 161 not taken.
19 .getWithFunctionParamAndReturnTypes(returnType, paramTypes)
622
1/2
✓ Branch 86 → 87 taken 19 times.
✗ Branch 86 → 161 not taken.
19 .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty());
623
624 // Create function object
625
2/4
✓ Branch 87 → 88 taken 19 times.
✗ Branch 87 → 165 not taken.
✓ Branch 88 → 89 taken 19 times.
✗ Branch 88 → 163 not taken.
19 const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn();
626
5/10
✓ Branch 91 → 92 taken 19 times.
✗ Branch 91 → 174 not taken.
✓ Branch 92 → 93 taken 19 times.
✗ Branch 92 → 171 not taken.
✓ Branch 93 → 94 taken 19 times.
✗ Branch 93 → 170 not taken.
✓ Branch 94 → 95 taken 19 times.
✗ Branch 94 → 168 not taken.
✓ Branch 95 → 96 taken 19 times.
✗ Branch 95 → 166 not taken.
19 node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node);
627
1/2
✓ Branch 101 → 102 taken 19 times.
✗ Branch 101 → 186 not taken.
19 node->manifestations.at(manIdx).bodyScope = bodyScope;
628
3/6
✓ Branch 102 → 103 taken 19 times.
✗ Branch 102 → 183 not taken.
✓ Branch 103 → 104 taken 19 times.
✗ Branch 103 → 181 not taken.
✓ Branch 104 → 105 taken 19 times.
✗ Branch 104 → 179 not taken.
19 node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx);
629
630 // Check special requirements if this is an async lambda
631
1/2
✓ Branch 108 → 109 taken 19 times.
✗ Branch 108 → 186 not taken.
19 (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr);
632
633
2/4
✓ Branch 109 → 110 taken 19 times.
✗ Branch 109 → 185 not taken.
✓ Branch 110 → 111 taken 19 times.
✗ Branch 110 → 185 not taken.
19 return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)};
634 23 }
635
636 39 std::any TypeChecker::visitLambdaProc(LambdaProcNode *node) {
637 // Mark unreachable statements
638 39 bool doSetPredecessorsUnreachable = true;
639
1/2
✓ Branch 2 → 3 taken 39 times.
✗ Branch 2 → 131 not taken.
39 node->returnsOnAllControlPaths(&doSetPredecessorsUnreachable, manIdx);
640
641 // Change to function scope
642
2/4
✓ Branch 3 → 4 taken 39 times.
✗ Branch 3 → 79 not taken.
✓ Branch 4 → 5 taken 39 times.
✗ Branch 4 → 77 not taken.
39 Scope *bodyScope = currentScope->getChildScope(node->getScopeId());
643
1/2
✓ Branch 6 → 7 taken 39 times.
✗ Branch 6 → 80 not taken.
39 ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY);
644
645 // Visit parameters
646 39 QualTypeList paramTypes;
647 39 ParamList paramList;
648
2/2
✓ Branch 7 → 8 taken 23 times.
✓ Branch 7 → 37 taken 16 times.
39 if (node->hasParams) {
649 // Visit param list to retrieve the param names
650
2/4
✓ Branch 8 → 9 taken 23 times.
✗ Branch 8 → 83 not taken.
✓ Branch 9 → 10 taken 23 times.
✗ Branch 9 → 81 not taken.
23 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
651
2/2
✓ Branch 34 → 13 taken 32 times.
✓ Branch 34 → 35 taken 23 times.
78 for (const auto &[_, qualType, isOptional] : namedParamList) {
652
2/2
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 23 taken 31 times.
32 if (isOptional)
653
2/4
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 86 not taken.
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 84 not taken.
2 softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters");
654
655
1/2
✓ Branch 23 → 24 taken 32 times.
✗ Branch 23 → 91 not taken.
32 paramTypes.push_back(qualType);
656
1/2
✓ Branch 24 → 25 taken 32 times.
✗ Branch 24 → 90 not taken.
32 paramList.push_back({qualType, isOptional});
657 }
658 23 }
659
660 // Visit lambda body
661
1/2
✓ Branch 37 → 38 taken 39 times.
✗ Branch 37 → 95 not taken.
39 visit(node->body);
662
663 // Leave function body scope
664
1/2
✓ Branch 39 → 40 taken 39 times.
✗ Branch 39 → 125 not taken.
39 scopeHandle.leaveScopeEarly();
665
666 // Prepare type of function
667
1/2
✓ Branch 40 → 41 taken 39 times.
✗ Branch 40 → 97 not taken.
39 const QualType functionType = QualType(TY_PROCEDURE)
668
2/4
✓ Branch 41 → 42 taken 39 times.
✗ Branch 41 → 96 not taken.
✓ Branch 42 → 43 taken 39 times.
✗ Branch 42 → 96 not taken.
39 .getWithFunctionParamAndReturnTypes(QualType(TY_DYN), paramTypes)
669
1/2
✓ Branch 44 → 45 taken 39 times.
✗ Branch 44 → 96 not taken.
39 .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty());
670
671 // Create function object
672
2/4
✓ Branch 45 → 46 taken 39 times.
✗ Branch 45 → 101 not taken.
✓ Branch 46 → 47 taken 39 times.
✗ Branch 46 → 99 not taken.
39 const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn();
673
6/12
✓ Branch 49 → 50 taken 39 times.
✗ Branch 49 → 111 not taken.
✓ Branch 50 → 51 taken 39 times.
✗ Branch 50 → 108 not taken.
✓ Branch 51 → 52 taken 39 times.
✗ Branch 51 → 107 not taken.
✓ Branch 52 → 53 taken 39 times.
✗ Branch 52 → 106 not taken.
✓ Branch 53 → 54 taken 39 times.
✗ Branch 53 → 104 not taken.
✓ Branch 54 → 55 taken 39 times.
✗ Branch 54 → 102 not taken.
39 node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), QualType(TY_DYN), paramList, {}, node);
674
1/2
✓ Branch 60 → 61 taken 39 times.
✗ Branch 60 → 123 not taken.
39 node->manifestations.at(manIdx).bodyScope = bodyScope;
675
3/6
✓ Branch 61 → 62 taken 39 times.
✗ Branch 61 → 120 not taken.
✓ Branch 62 → 63 taken 39 times.
✗ Branch 62 → 118 not taken.
✓ Branch 63 → 64 taken 39 times.
✗ Branch 63 → 116 not taken.
39 node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx);
676
677 // Check special requirements if this is an async lambda
678
1/2
✓ Branch 67 → 68 taken 39 times.
✗ Branch 67 → 123 not taken.
39 (void)checkAsyncLambdaCaptureRules(node, node->lambdaAttr);
679
680
2/4
✓ Branch 68 → 69 taken 39 times.
✗ Branch 68 → 122 not taken.
✓ Branch 69 → 70 taken 39 times.
✗ Branch 69 → 122 not taken.
78 return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)};
681 39 }
682
683 1 std::any TypeChecker::visitLambdaExpr(LambdaExprNode *node) {
684 // Change to function scope
685
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 98 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 96 not taken.
1 Scope *bodyScope = currentScope->getChildScope(node->getScopeId());
686
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 99 not taken.
1 ScopeHandle scopeHandle(this, bodyScope, ScopeType::LAMBDA_BODY);
687
688 // Visit parameters
689 1 QualTypeList paramTypes;
690 1 ParamList paramList;
691
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 36 not taken.
1 if (node->hasParams) {
692 // Visit param list to retrieve the param names
693
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 102 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 100 not taken.
1 auto namedParamList = std::any_cast<NamedParamList>(visit(node->paramLst));
694
2/2
✓ Branch 33 → 12 taken 2 times.
✓ Branch 33 → 34 taken 1 time.
4 for (const NamedParam &param : namedParamList) {
695
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 22 taken 2 times.
2 if (param.isOptional)
696 softError(node, LAMBDA_WITH_OPTIONAL_PARAMS, "Lambdas cannot have optional parameters");
697
698
1/2
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 110 not taken.
2 paramTypes.push_back(param.qualType);
699
1/2
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 109 not taken.
2 paramList.push_back({param.qualType, param.isOptional});
700 }
701 1 }
702
703 // Visit lambda expression
704
2/4
✓ Branch 36 → 37 taken 1 time.
✗ Branch 36 → 116 not taken.
✓ Branch 37 → 38 taken 1 time.
✗ Branch 37 → 114 not taken.
1 const QualType returnType = std::any_cast<ExprResult>(visit(node->lambdaExpr)).type;
705
2/8
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 153 not taken.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 45 taken 1 time.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 118 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 118 not taken.
1 HANDLE_UNRESOLVED_TYPE_ER(returnType)
706
2/4
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 153 not taken.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 57 taken 1 time.
1 if (returnType.is(TY_DYN))
707 SOFT_ERROR_ER(node, UNEXPECTED_DYN_TYPE, "Dyn return types are not allowed")
708
709 // Leave function body scope
710
1/2
✓ Branch 57 → 58 taken 1 time.
✗ Branch 57 → 153 not taken.
1 scopeHandle.leaveScopeEarly();
711
712 // Prepare type of function
713
2/4
✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 153 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 1 time.
1 const SuperType superType = returnType.is(TY_DYN) ? TY_PROCEDURE : TY_FUNCTION;
714
1/2
✓ Branch 62 → 63 taken 1 time.
✗ Branch 62 → 126 not taken.
1 const QualType functionType = QualType(superType)
715
1/2
✓ Branch 63 → 64 taken 1 time.
✗ Branch 63 → 126 not taken.
1 .getWithFunctionParamAndReturnTypes(returnType, paramTypes)
716
1/2
✓ Branch 65 → 66 taken 1 time.
✗ Branch 65 → 126 not taken.
1 .getWithLambdaCaptures(!bodyScope->symbolTable.captures.empty());
717
718 // Create function object
719
2/4
✓ Branch 66 → 67 taken 1 time.
✗ Branch 66 → 130 not taken.
✓ Branch 67 → 68 taken 1 time.
✗ Branch 67 → 128 not taken.
1 const std::string fctName = "lambda." + node->codeLoc.toPrettyLineAndColumn();
720
5/10
✓ Branch 70 → 71 taken 1 time.
✗ Branch 70 → 139 not taken.
✓ Branch 71 → 72 taken 1 time.
✗ Branch 71 → 136 not taken.
✓ Branch 72 → 73 taken 1 time.
✗ Branch 72 → 135 not taken.
✓ Branch 73 → 74 taken 1 time.
✗ Branch 73 → 133 not taken.
✓ Branch 74 → 75 taken 1 time.
✗ Branch 74 → 131 not taken.
1 node->manifestations.at(manIdx) = Function(fctName, nullptr, QualType(TY_DYN), returnType, paramList, {}, node);
721
1/2
✓ Branch 80 → 81 taken 1 time.
✗ Branch 80 → 151 not taken.
1 node->manifestations.at(manIdx).bodyScope = bodyScope;
722
3/6
✓ Branch 81 → 82 taken 1 time.
✗ Branch 81 → 148 not taken.
✓ Branch 82 → 83 taken 1 time.
✗ Branch 82 → 146 not taken.
✓ Branch 83 → 84 taken 1 time.
✗ Branch 83 → 144 not taken.
1 node->manifestations.at(manIdx).mangleSuffix = "." + std::to_string(manIdx);
723
724
2/4
✓ Branch 87 → 88 taken 1 time.
✗ Branch 87 → 150 not taken.
✓ Branch 88 → 89 taken 1 time.
✗ Branch 88 → 150 not taken.
1 return ExprResult{node->setEvaluatedSymbolType(functionType, manIdx)};
725 1 }
726
727 } // namespace spice::compiler
728