aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp108
1 files changed, 98 insertions, 10 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index e11014a70..2d0b9dfa9 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -6168,7 +6168,9 @@ gb_internal CallArgumentError check_call_arguments_internal(CheckerContext *c, A
Type *t = elem;
if (is_type_polymorphic(t)) {
- error(call, "Ambiguous call to a polymorphic variadic procedure with no variadic input %s", type_to_string(final_proc_type));
+ if (show_error) {
+ error(call, "Ambiguous call to a polymorphic variadic procedure with no variadic input %s", type_to_string(final_proc_type));
+ }
err = CallArgumentError_AmbiguousPolymorphicVariadic;
}
@@ -6800,9 +6802,73 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
if (procs.count > 0) {
error_line("Did you mean to use one of the following:\n");
}
+
+ // Try to reduce the list further for `$T: typeid` like parameters
+ bool *possibly_ignore = gb_alloc_array(temporary_allocator(), bool, procs.count);
+ isize possibly_ignore_set = 0;
+
+ if (true) {
+ // NOTE(bill): This currently only checks for #soa types
+ for_array(i, procs) {
+ Entity *proc = procs[i];
+ Type *t = base_type(proc->type);
+ if (t == nullptr || t->kind != Type_Proc) {
+ continue;
+ }
+
+ TypeProc *pt = &t->Proc;
+ if (pt->param_count == 0) {
+ continue;
+ }
+
+ for_array(j, pt->params->Tuple.variables) {
+ Entity *v = pt->params->Tuple.variables[j];
+ if (v->kind != Entity_TypeName) {
+ continue;
+ }
+
+ Type *dst_t = base_type(v->type);
+ while (dst_t->kind == Type_Generic && dst_t->Generic.specialized) {
+ dst_t = dst_t->Generic.specialized;
+ }
+
+ if (j >= positional_operands.count) {
+ continue;
+ }
+ Operand const &o = positional_operands[j];
+ if (o.mode != Addressing_Type) {
+ continue;
+ }
+ Type *t = base_type(o.type);
+ if (t->kind == dst_t->kind) {
+ continue;
+ }
+ Type *st = base_type(type_deref(o.type));
+ Type *dt = base_type(type_deref(dst_t));
+ if (st->kind == dt->kind) {
+ continue;
+ }
+ if (is_type_soa_struct(st)) {
+ possibly_ignore[i] = true;
+ possibly_ignore_set += 1;
+ continue;
+ }
+ }
+ }
+ }
+
+ if (possibly_ignore_set == procs.count) {
+ possibly_ignore_set = 0;
+ }
+
+
isize max_name_length = 0;
isize max_type_length = 0;
- for (Entity *proc : procs) {
+ for_array(i, procs) {
+ if (possibly_ignore_set != 0 && possibly_ignore[i]) {
+ continue;
+ }
+ Entity *proc = procs[i];
Type *t = base_type(proc->type);
if (t == t_invalid) continue;
String prefix = {};
@@ -6832,7 +6898,11 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
}
spaces[max_spaces] = 0;
- for (Entity *proc : procs) {
+ for_array(i, procs) {
+ if (possibly_ignore_set != 0 && possibly_ignore[i]) {
+ continue;
+ }
+ Entity *proc = procs[i];
TokenPos pos = proc->token.pos;
Type *t = base_type(proc->type);
if (t == t_invalid) continue;
@@ -9055,12 +9125,16 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
type = nullptr;
// [?]Type
- if (type_expr->kind == Ast_ArrayType && type_expr->ArrayType.count != nullptr) {
+ if (type_expr->kind == Ast_ArrayType) {
Ast *count = type_expr->ArrayType.count;
- if (count->kind == Ast_UnaryExpr &&
- count->UnaryExpr.op.kind == Token_Question) {
- type = alloc_type_array(check_type(c, type_expr->ArrayType.elem), -1);
- is_to_be_determined_array_count = true;
+ if (count != nullptr) {
+ if (count->kind == Ast_UnaryExpr &&
+ count->UnaryExpr.op.kind == Token_Question) {
+ type = alloc_type_array(check_type(c, type_expr->ArrayType.elem), -1);
+ is_to_be_determined_array_count = true;
+ }
+ } else {
+ type = alloc_type_slice(check_type(c, type_expr->ArrayType.elem));
}
if (cl->elems.count > 0) {
if (type_expr->ArrayType.tag != nullptr) {
@@ -9073,8 +9147,7 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
}
}
}
- }
- if (type_expr->kind == Ast_DynamicArrayType && type_expr->DynamicArrayType.tag != nullptr) {
+ } else if (type_expr->kind == Ast_DynamicArrayType && type_expr->DynamicArrayType.tag != nullptr) {
if (cl->elems.count > 0) {
Ast *tag = type_expr->DynamicArrayType.tag;
GB_ASSERT(tag->kind == Ast_BasicDirective);
@@ -9113,6 +9186,12 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
if (cl->elems.count == 0) {
break; // NOTE(bill): No need to init
}
+
+ if (t->Struct.soa_kind != StructSoa_None) {
+ error(node, "#soa arrays are not supported for compound literals");
+ break;
+ }
+
if (t->Struct.is_raw_union) {
if (cl->elems.count > 0) {
// NOTE: unions cannot be constant
@@ -11414,6 +11493,9 @@ gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthan
case_end;
case_ast_node(pt, PointerType, node);
+ if (pt->tag) {
+ str = write_expr_to_string(str, pt->tag, false);
+ }
str = gb_string_append_rune(str, '^');
str = write_expr_to_string(str, pt->type, shorthand);
case_end;
@@ -11424,6 +11506,9 @@ gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthan
case_end;
case_ast_node(at, ArrayType, node);
+ if (at->tag) {
+ str = write_expr_to_string(str, at->tag, false);
+ }
str = gb_string_append_rune(str, '[');
if (at->count != nullptr &&
at->count->kind == Ast_UnaryExpr &&
@@ -11437,6 +11522,9 @@ gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthan
case_end;
case_ast_node(at, DynamicArrayType, node);
+ if (at->tag) {
+ str = write_expr_to_string(str, at->tag, false);
+ }
str = gb_string_appendc(str, "[dynamic]");
str = write_expr_to_string(str, at->elem, shorthand);
case_end;