bugfix: js platform and `void` structure literals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Mar 2023 20:30:41 +0000 (15:30 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Mar 2023 20:30:41 +0000 (15:30 -0500)
compiler/src/checker.c
compiler/src/wasm_emit.c
core/runtime/platform/js/platform.onyx

index b9f6fbe3a6e1f18837cfa37556c1d3ae4d071908..a60be7c61b374090f36872710743c6fe29e6d1b4 100644 (file)
@@ -1447,6 +1447,11 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) {
         // If there are no given arguments to a structure literal, it is treated as a 'zero-value',
         // and can be used to create a completely zeroed value of any type.
         if (bh_arr_length(sl->args.values) == 0 && bh_arr_length(sl->args.named_values) == 0) {
+            if (sl->type->kind == Type_Kind_Basic &&
+                sl->type->Basic.kind == Basic_Kind_Void) {
+                ERROR(sl->token->pos, "Cannot produce a zero-value for 'void' type.");
+            }
+
             AstZeroValue *zv = make_zero_value(context.ast_alloc, sl->token, sl->type);
             bh_arr_push(sl->args.values, (AstTyped *) zv);
 
index 1fda5143ef43019c0dadc4f661e3bae1e4cd8ad1..1fa595273eb895d499568ed341fcda256592ab61 100644 (file)
@@ -4145,6 +4145,10 @@ static char encode_type_as_dyncall_symbol(Type *t) {
         if (basic->size == 0) return 'v';
     }
 
+    if (t->kind == Type_Kind_Distinct) {
+        return encode_type_as_dyncall_symbol(t->Distinct.base_type);
+    }
+
     return 'v';
 }
 
index aa304e2a7fc77594ae1e1ebf1770070770c680fb..38b01b7f0fe04b5906e1d1a619f08a9a8e3f86b6 100644 (file)
@@ -4,8 +4,6 @@ use core
 use runtime {
     __runtime_initialize,
     Multi_Threading_Enabled,
-    _thread_start,
-    _thread_exit
 }
 
 // Platform supports
@@ -43,6 +41,6 @@ __start :: () {
     __spawn_thread :: (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) -> bool #foreign "host" "spawn_thread" ---
     __kill_thread  :: (id: i32) -> i32 #foreign "host" "kill_thread" ---
 
-    #export "_thread_start" _thread_start
-    #export "_thread_exit"  _thread_exit
+    #export "_thread_start" runtime._thread_start
+    #export "_thread_exit"  runtime._thread_exit
 }