Skip to content

Commit

Permalink
Fix bug that caused crash in TypeChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Nov 25, 2022
1 parent 954a2e4 commit 2120db4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions media/test-project/os-test.spice
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
f<int> fibo(int n) {
if n <= 1 { return n; }
return fibo(n - 1) + fibo(n - 2);
f<bool> isValid(int input = 12) {
printf("This is a test");
}

f<int> main() {
printf("Result: %d", fibo(30));
bool isValid = isValid();
printf("Is valid: %d", isValid);
}

/*type NotAPointer struct {}
Expand Down
4 changes: 2 additions & 2 deletions src/typechecker/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,8 @@ std::any TypeChecker::visitArrayInitialization(ArrayInitializationNode *node) {
long actualSize = 0;
if (node->itemLst()) {
actualSize = (long)node->itemLst()->args().size();
for (const auto &arg : node->itemLst()->args()) {
const auto itemType = std::any_cast<SymbolType>(visit(arg));
for (AssignExprNode *arg : node->itemLst()->args()) {
const SymbolType itemType = std::any_cast<ExprResult>(visit(arg)).type;
if (actualItemType.is(TY_DYN)) // Perform type inference
actualItemType = itemType;
else if (itemType != actualItemType) // Check if types are matching
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Error|Semantic] ./test-files/analyzer/foreach-loops/error-foreach-wrong-index-type/source.spice:3:13:
Array index not of type int or long: Index in foreach loop must be of type int. You provided double
Array index not of type int: Index in foreach loop must be of type int. You provided double

3 foreach double i, int item : array {
^^^^^^^^

0 comments on commit 2120db4

Please sign in to comment.