From: Brendan Hansen Date: Wed, 6 Jan 2021 18:08:59 +0000 (-0600) Subject: default values are no longer immediately type checked X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8e7828878a4a1da9635ae6d91420ab8275e3aba1;p=onyx.git default values are no longer immediately type checked --- diff --git a/bin/onyx b/bin/onyx index 75d65de0..739ae347 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/map.onyx b/core/map.onyx index ceae9041..74fc99ed 100644 --- a/core/map.onyx +++ b/core/map.onyx @@ -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); diff --git a/onyx.exe b/onyx.exe index 512452fb..0988e707 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 707e7546..159cbaa5 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1555,15 +1555,19 @@ CheckStatus check_function_header(AstFunction* func) { return Check_Error; } - if (param->default_value != NULL) { - if (!type_check_or_auto_cast(¶m->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(¶m->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;