fixed: code generation bug when a local's type is `void`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 18:08:03 +0000 (12:08 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 18:08:03 +0000 (12:08 -0600)
compiler/src/checker.c

index 4f929d2a27cfea128816717dd0ca3af67a625519..e81a923f42bac39e4a8e7a4cf23cb0409e065704 100644 (file)
@@ -1107,6 +1107,10 @@ CheckStatus check_binaryop_assignment(AstBinaryOp** pbinop) {
                 }
 
             } else {
+                if (right_type == &basic_types[Basic_Kind_Void]) {
+                    ERROR(binop->left->token->pos, "Due to inference, this variables type would be 'void', which is not allowed.");
+                }
+
                 binop->left->type = right_type;
             }
         }
@@ -2799,6 +2803,11 @@ CheckStatus check_statement(AstNode** pstmt) {
                     typed_stmt->flags |= Ast_Flag_Decl_Followed_By_Init;
                 }
             }
+            
+            if (typed_stmt->type != NULL && typed_stmt->type == &basic_types[Basic_Kind_Void]) {
+                ERROR(stmt->token->pos, "This local variable has a type of 'void', which is not allowed.");
+            }
+
             return Check_Success;
         }