default values are no longer immediately type checked
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 6 Jan 2021 18:08:59 +0000 (12:08 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 6 Jan 2021 18:08:59 +0000 (12:08 -0600)
bin/onyx
core/map.onyx
onyx.exe
src/onyxchecker.c

index 75d65de0283e28d944bf073842f5e26ec67bb665..739ae347614d885902bcf955dc31a2d001078777 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index ceae9041ed2075950f006761dcba991e43308679..74fc99edcb21aed571d7a070c4499468243832ce 100644 (file)
@@ -18,7 +18,7 @@ MapEntry :: struct ($K, $T) {
     value : T;
 }
 
-init :: proc (use map: ^Map($K, $V), dv: V, hash_count: i32 = 16) {
+init :: proc (use map: ^Map($K, $V), dv: V = ~~0, hash_count: i32 = 16) {
     array.init(^hashes, hash_count);
     array.init(^entries, 4);
 
index 512452fb5000ffb1b48c997066ebfd0608948d1e..0988e70770ce6608b280d5b1d660029239e67410 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 707e754619fcc2fe51f3b8b7b7e12d033e2e127f..159cbaa5b8c93f686785294c6db7901f47f15d57 100644 (file)
@@ -1555,15 +1555,19 @@ CheckStatus check_function_header(AstFunction* func) {
             return Check_Error;
         }
 
-        if (param->default_value != NULL) {
-            if (!type_check_or_auto_cast(&param->default_value, param->local->type)) {
-                onyx_report_error(param->local->token->pos,
-                        "Expected default value of type '%s', was of type '%s'.",
-                        type_get_name(param->local->type),
-                        type_get_name(param->default_value->type));
-                return Check_Error;
-            }
-        }
+        // NOTE: I decided to make parameter default values not type checked against
+        // the actual parameter type. The actual type checking will happen in check_call
+        // when the default value is used as an argument and then has to be checked against
+        // the parameter type                                  - brendanfh 2021/01/06
+        // if (param->default_value != NULL) {
+        //     if (!type_check_or_auto_cast(&param->default_value, param->local->type)) {
+        //         onyx_report_error(param->local->token->pos,
+        //                 "Expected default value of type '%s', was of type '%s'.",
+        //                 type_get_name(param->local->type),
+        //                 type_get_name(param->default_value->type));
+        //         return Check_Error;
+        //     }
+        // }
 
         if (param->vararg_kind != VA_Kind_Not_VA) has_had_varargs = 1;