Skip to content

Commit d65b1d5

Browse files
committed
Better proc groups inference
1 parent 38187ef commit d65b1d5

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/check_expr.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5896,8 +5896,9 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize
58965896

58975897
bool allow_ok = (flags & UnpackFlag_AllowOk) != 0;
58985898
bool allow_undef = (flags & UnpackFlag_AllowUndef) != 0;
5899-
5900-
if (variadic_index < 0) {
5899+
5900+
bool is_variadic = variadic_index > -1;
5901+
if (!is_variadic) {
59015902
variadic_index = lhs_count;
59025903
}
59035904

@@ -5916,25 +5917,18 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize
59165917

59175918
Type *type_hint = nullptr;
59185919

5919-
if (lhs != nullptr && tuple_index < variadic_index) {
5920-
// NOTE(bill): override DeclInfo for dependency
5921-
Entity *e = lhs[tuple_index];
5922-
if (e != nullptr) {
5923-
type_hint = e->type;
5924-
if (e->flags & EntityFlag_Ellipsis) {
5925-
GB_ASSERT(is_type_slice(e->type));
5926-
GB_ASSERT(e->type->kind == Type_Slice);
5927-
type_hint = e->type->Slice.elem;
5920+
if (lhs != nullptr) {
5921+
if (tuple_index < variadic_index) {
5922+
// NOTE(bill): override DeclInfo for dependency
5923+
Entity *e = lhs[tuple_index];
5924+
if (e != nullptr) {
5925+
type_hint = e->type;
59285926
}
5929-
}
5930-
} else if (lhs != nullptr && tuple_index >= variadic_index) {
5931-
// NOTE(bill): override DeclInfo for dependency
5932-
Entity *e = lhs[variadic_index];
5933-
if (e != nullptr) {
5934-
type_hint = e->type;
5935-
if (e->flags & EntityFlag_Ellipsis) {
5927+
} else if (is_variadic) {
5928+
Entity *e = lhs[variadic_index];
5929+
if (e != nullptr) {
5930+
GB_ASSERT(e->flags & EntityFlag_Ellipsis);
59365931
GB_ASSERT(is_type_slice(e->type));
5937-
GB_ASSERT(e->type->kind == Type_Slice);
59385932
type_hint = e->type->Slice.elem;
59395933
}
59405934
}
@@ -6822,11 +6816,12 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
68226816

68236817
if (procs.count == 1) {
68246818
Entity *e = procs[0];
6825-
TypeProc *pt = &base_type(e->type)->Proc;
6826-
6827-
lhs = populate_proc_parameter_list(c, e->type, &lhs_count);
6828-
if (pt->variadic) {
6829-
variadic_index = pt->variadic_index;
6819+
Type *pt = base_type(e->type);
6820+
if (pt != nullptr && is_type_proc(pt)) {
6821+
lhs = populate_proc_parameter_list(c, pt, &lhs_count);
6822+
if (pt->Proc.variadic) {
6823+
variadic_index = pt->Proc.variadic_index;
6824+
}
68306825
}
68316826
check_unpack_arguments(c, lhs, lhs_count, &positional_operands, positional_args, UnpackFlag_None, variadic_index);
68326827

@@ -6888,6 +6883,25 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
68886883
}
68896884
lhs[param_index] = e;
68906885
}
6886+
6887+
for (Entity *p : procs) {
6888+
Type *pt = base_type(p->type);
6889+
if (!(pt != nullptr && is_type_proc(pt))) {
6890+
continue;
6891+
}
6892+
6893+
if (pt->Proc.is_polymorphic) {
6894+
if (variadic_index == -1) {
6895+
variadic_index = pt->Proc.variadic_index;
6896+
} else if (variadic_index != pt->Proc.variadic_index) {
6897+
variadic_index = -1;
6898+
break;
6899+
}
6900+
} else {
6901+
variadic_index = -1;
6902+
break;
6903+
}
6904+
}
68916905
}
68926906
}
68936907
}
@@ -7330,8 +7344,8 @@ gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *op
73307344
defer (array_free(&named_operands));
73317345

73327346
if (positional_args.count > 0) {
7333-
isize lhs_count = -1;
73347347
Entity **lhs = nullptr;
7348+
isize lhs_count = -1;
73357349
i32 variadic_index = -1;
73367350
if (pt != nullptr) {
73377351
lhs = populate_proc_parameter_list(c, proc_type, &lhs_count);

0 commit comments

Comments
 (0)