b32 type_is_structlike_strict(Type* type);
u32 type_structlike_mem_count(Type* type);
u32 type_structlike_is_simple(Type* type);
+b32 type_is_sl_constructable(Type* type);
#endif // #ifndef ONYX_TYPES
if (node->kind == Ast_Kind_Struct_Literal && node->type_node == NULL) {
if (type->kind == Type_Kind_VarArgs) type = type->VarArgs.ptr_to_data->Pointer.elem;
+ if (!type_is_sl_constructable(type)) return 0;
+
node->type = type;
add_entities_for_node(NULL, (AstNode *) node, NULL, NULL);
bh_arr_each(AstTyped *, value, sl->args.values) {
if (*value == NULL) {
i32 member_idx = value - sl->args.values; // Pointer subtraction hack
+ StructMember smem;
+ type_lookup_member_by_idx(sl->type, member_idx, &smem);
onyx_report_error(sl->token->pos,
- "Value not given for %d%s member, '%s'.",
+ "Value not given for %d%s member, '%s', for type '%s'.",
member_idx + 1, bh_num_suffix(member_idx + 1),
- sl->type->Struct.memarr[member_idx]->name);
+ smem.name, type_get_name(sl->type));
}
}
default: return 0;
}
}
+
+b32 type_is_sl_constructable(Type* type) {
+ switch (type->kind) {
+ case Type_Kind_Struct: return 1;
+ case Type_Kind_Slice: return 1;
+ case Type_Kind_DynArray: return 1;
+ default: return 0;
+ }
+}
// * Resolving an overload from a TypeFunction (so an overloaded procedure can be passed as a parameter)
//
+// NOTE: The job of this function is to take a set of overloads, and traverse it to add all possible
+// overloads that are reachable. This is slightly more difficult than it may seem. In this language,
+// overloaded procedures have a strict ordering to their overloads, which determines how the correct
+// match will be found. This was not very complicated until overloaded procedures could be used as
+// overload options. This means that you could create an "infinite loop" of overloads like so:
+//
+// o1 :: { o2 :: {
+// (...) { ... }, (...) { ... },
+// o2 o1
+// } }
+//
+// Obviously, this is not really an infinite loop. It just means that all options are available if
+// o1 or o2 are called. The difference between o1 and o2 is the order that the overloads will be
+// searched. To build the the list of overloads, a hashmap is used to prevent the problem from being
+// O(n^2), even though n would (probably) be small. bh_imap has the useful property that it maintains
+// an "entries" array that, so long as nothing is ever removed from it, will maintain the order in
+// which entries were put into the map. This is useful because a simple recursive algorithm can
+// collect all the overloads into the map, and also use the map to provide a base case.
static void build_all_overload_options(bh_arr(AstTyped *) overloads, bh_imap* all_overloads) {
bh_arr_each(AstTyped *, node, overloads) {
if (bh_imap_has(all_overloads, (u64) *node)) continue;