added: error message when a type inferred struct literal fails
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 30 Dec 2023 23:49:22 +0000 (17:49 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 30 Dec 2023 23:49:22 +0000 (17:49 -0600)
This is untested in larger code bases if this actually makes a quality of life improvement

compiler/include/types.h
compiler/src/astnodes.c
compiler/src/types.c

index 3df4e5d12c11324b5731568a94c2c07a602e7432..bf9d363eff54ade6228f9331f69e118ffc798720 100644 (file)
@@ -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);
index b7e17d9327fe51abdc268275354577ee70fe847d..90efc63e12f6cebe086c1985a9fc026a1d7ff299 100644 (file)
@@ -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);
         }
index 9f0d41e194ab6856881a95f37591b4cec4198028..ce748406e22bdbd528e503d7c0eccd00a7033be2 100644 (file)
@@ -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;
         }