From 62623e61b950d6cd80b822ce2b7998fa17e864da Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 30 Dec 2023 17:49:22 -0600 Subject: [PATCH] added: error message when a type inferred struct literal fails This is untested in larger code bases if this actually makes a quality of life improvement --- compiler/include/types.h | 2 +- compiler/src/astnodes.c | 4 ++-- compiler/src/types.c | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/include/types.h b/compiler/include/types.h index 3df4e5d1..bf9d363e 100644 --- a/compiler/include/types.h +++ b/compiler/include/types.h @@ -233,7 +233,7 @@ b32 types_are_compatible(Type* t1, Type* t2); u32 type_size_of(Type* type); u32 type_alignment_of(Type* type); Type* type_build_from_ast(bh_allocator alloc, struct AstType* type_node); -Type* type_build_implicit_type_of_struct_literal(bh_allocator alloc, struct AstStructLiteral* lit); +Type* type_build_implicit_type_of_struct_literal(bh_allocator alloc, struct AstStructLiteral* lit, b32 is_query); Type* type_build_function_type(bh_allocator alloc, struct AstFunction* func); Type* type_build_compound_type(bh_allocator alloc, struct AstCompound* compound); diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index b7e17d93..90efc63e 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -1039,7 +1039,7 @@ Type* query_expression_type(AstTyped *node) { return NULL; } - return type_build_implicit_type_of_struct_literal(context.ast_alloc, sl); + return type_build_implicit_type_of_struct_literal(context.ast_alloc, sl, 1); } // If polymorphic procedures HAVE to have a type, most likely @@ -1145,7 +1145,7 @@ Type* resolve_expression_type(AstTyped* node) { return NULL; } - sl->type = type_build_implicit_type_of_struct_literal(context.ast_alloc, sl); + sl->type = type_build_implicit_type_of_struct_literal(context.ast_alloc, sl, 0); if (sl->type) { add_entities_for_node(NULL, (AstNode *) sl, NULL, NULL); } diff --git a/compiler/src/types.c b/compiler/src/types.c index 9f0d41e1..ce748406 100644 --- a/compiler/src/types.c +++ b/compiler/src/types.c @@ -921,7 +921,7 @@ Type* type_build_compound_type(bh_allocator alloc, AstCompound* compound) { return comp_type; } -Type* type_build_implicit_type_of_struct_literal(bh_allocator alloc, AstStructLiteral* lit) { +Type* type_build_implicit_type_of_struct_literal(bh_allocator alloc, AstStructLiteral* lit, b32 is_query) { if (lit->generated_inferred_type) { return lit->generated_inferred_type; } @@ -949,6 +949,10 @@ Type* type_build_implicit_type_of_struct_literal(bh_allocator alloc, AstStructLi Type* member_type = resolve_expression_type(nv->value); if (member_type == NULL) { + if (!is_query) { + onyx_report_error(nv->value->token->pos, Error_Critical, "Unable to resolve type of this member when trying to construct an inferred type of the structure literal."); + } + return NULL; } -- 2.25.1