fixed: incorrect WASM binary; refined error messages
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 20:10:23 +0000 (14:10 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 20:10:23 +0000 (14:10 -0600)
compiler/src/checker.c
compiler/src/wasm_emit.c

index e81a923f42bac39e4a8e7a4cf23cb0409e065704..363edabd0c28112cacaff6eba3eee5256314ae7a 100644 (file)
@@ -1100,6 +1100,10 @@ CheckStatus check_binaryop_assignment(AstBinaryOp** pbinop) {
 
                 } else {
                     fori (i, 0, store_expr_count) {
+                        if (right_type->Compound.types[i] == &basic_types[Basic_Kind_Void]) {
+                            ERROR(lhs->exprs[i]->token->pos, "Due to inference, this variables type would be 'void', which is not allowed.");
+                        }
+
                         TRY_ASSIGN_TYPE_OR_FAIL(&lhs->exprs[i], right_type->Compound.types[i], binop->token);
                     }
 
@@ -3293,7 +3297,7 @@ CheckStatus check_function_header(AstFunction* func) {
         if (param->vararg_kind != VA_Kind_Not_VA) has_had_varargs = 1;
 
         if (local->type->kind != Type_Kind_Array && type_size_of(local->type) == 0) {
-            ERROR(local->token->pos, "Function parameters cannot have zero-width types.");
+            ERROR(local->token->pos, "Function parameters cannot have 'void' as their type.");
         }
     }
 
index 1be603707b7daf57ba158665514cebb8acca5e89..95b51ef3a1753598e55770a36dbdd0d762159bb5 100644 (file)
@@ -1129,6 +1129,10 @@ EMIT_FUNC(load_instruction, Type* type, u32 offset) {
     else if (is_basic && (type->Basic.flags & Basic_Flag_SIMD)) {
         instr = WI_V128_LOAD;
     }
+    else if (is_basic && (type->Basic.kind == Basic_Kind_Void)) {
+        // Do nothing to "load" a void type.
+        return;
+    }
 
     WID(NULL, instr, ((WasmInstructionData) { alignment, offset }));