diff options
| author | CiD- <jkercher43@gmail.com> | 2022-04-08 13:50:06 -0400 |
|---|---|---|
| committer | CiD- <jkercher43@gmail.com> | 2022-04-08 13:50:06 -0400 |
| commit | 56737c14314f541762f9adba78a33ac28036ec8c (patch) | |
| tree | e4df7b8bb3199aa04cb568f6007f54e5bc97cb3c /src/check_type.cpp | |
| parent | 9ae566adcc5e7e55039349eed2b4768739391ae8 (diff) | |
| parent | f2f1330238d46bb6e80eac33da99604ac2f99a52 (diff) | |
merge upstream/master
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index ecb2c26ea..51f472961 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -675,22 +675,31 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op } if (ok) { array_add(&variants, t); + + if (ut->kind == UnionType_shared_nil) { + if (!type_has_nil(t)) { + gbString s = type_to_string(t); + error(node, "Each variant of a union with #shared_nil must have a 'nil' value, got %s", s); + gb_string_free(s); + } + } } } } union_type->Union.variants = slice_from_array(variants); - union_type->Union.no_nil = ut->no_nil; - union_type->Union.maybe = ut->maybe; - if (union_type->Union.no_nil) { + union_type->Union.kind = ut->kind; + switch (ut->kind) { + case UnionType_no_nil: if (variants.count < 2) { error(ut->align, "A union with #no_nil must have at least 2 variants"); } - } - if (union_type->Union.maybe) { + break; + case UnionType_maybe: if (variants.count != 1) { error(ut->align, "A union with #maybe must have at 1 variant, got %lld", cast(long long)variants.count); } + break; } if (ut->align != nullptr) { @@ -1960,20 +1969,6 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, if (params) param_count = params ->Tuple.variables.count; if (results) result_count = results->Tuple.variables.count; - if (param_count > 0) { - for_array(i, params->Tuple.variables) { - Entity *param = params->Tuple.variables[i]; - if (param->kind == Entity_Variable) { - ParameterValue pv = param->Variable.param_value; - if (pv.kind == ParameterValue_Constant && - pv.value.kind == ExactValue_Procedure) { - type->Proc.has_proc_default_values = true; - break; - } - } - } - } - if (result_count > 0) { Entity *first = results->Tuple.variables[0]; type->Proc.has_named_results = first->token.string != ""; |