small bugfixes with error message production
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 24 Jan 2021 05:56:07 +0000 (23:56 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 24 Jan 2021 05:56:07 +0000 (23:56 -0600)
bin/onyx
onyx.exe
src/onyxastnodes.c
src/onyxsymres.c
src/onyxtypes.c
src/onyxutils.c

index f4d0eb568cb89ffd6a7743904b2c8a29498c13b2..74d7969d247fc2f379c677c13d5013f4027d02c6 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index c8e01198df0113707e7855be0876f69dcb295346..6949f75b40b039b4e4cd720a23ab428c6e9aa645 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 1518a750fb61c53acf4e07a73d726159de465c98..1ea640df011cf2c6c01afee5c4bbd67d15e8974b 100644 (file)
@@ -28,7 +28,7 @@ static const char* ast_node_names[] = {
     "BIN_OP",
 
     "COMPOUND",
-    "NAMED_VALUE"
+    "NAMED_VALUE",
 
     "TYPE_START (BAD)",
     "TYPE",
index 4024070c25492b01e01146b2b4ecc8b3d14325dc..8b4d61e57b0129dfa509a1128c8330ebea84b334 100644 (file)
@@ -695,12 +695,30 @@ void symres_function_header(AstFunction* func) {
     scope_enter(func->scope);
 
     bh_arr_each(AstParam, param, func->params) {
+        symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local);
+
+        // CLEANUP: Currently, in order to 'use' parameters, the type must be completely
+        // resolved and built. This is excessive because all that should need to be known
+        // is the names of the members, since all that happens is implicit field accesses
+        // are placed in the scope. So instead, there should be a way to just query all the
+        // member names in the structure, without needing to know their type. This would be
+        // easy if it were not for 'use' statements in structs. It is made even more complicated
+        // by this situtation:
+        //
+        //     Foo :: struct (T: type_expr) {
+        //         use t : T;
+        // 
+        //         something_else := 5 + 6 * 8;
+        //     }
+        //
+        // The 'use t : T' member requires completely knowing the type of T, to know which
+        // members should be brought in. At the moment, that requires completely building the
+        // type of Foo($T), which is not possible, because the defaulted member 'something_else'
+        // does not have a known type until the default memory gets checked and reduced.
         if (param->local->type_node != NULL) {
             param->local->type_node = symres_type(param->local->type_node);
         }
 
-        symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local);
-
         if (param->local->flags & Ast_Flag_Param_Use) {
             if (param->local->type_node != NULL && param->local->type == NULL) {
                 param->local->type = type_build_from_ast(context.ast_alloc, param->local->type_node);
index 6b304ed07ee40434110864da40ef47e047d81860..eefe755c9ec11dbfc780217aea28b88c3a40fa86 100644 (file)
@@ -530,6 +530,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) {
             // CLEANUP: Maybe don't copy it and just use this one since it is allocated on the heap?
             bh_arr_free(slns);
 
+            if (!concrete) return NULL;
             return type_build_from_ast(alloc, (AstType *) concrete);
         }
 
index 8dd71292f02863a62b03d3f482510794cdf21213..a8a3a65f8ad6ab05e048e6e4cb15f661b0d02992 100644 (file)
@@ -955,7 +955,6 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP
     insert_poly_slns_into_scope(ps_type->scope, slns);
 
     AstStructType* concrete_struct = (AstStructType *) ast_clone(context.ast_alloc, ps_type->base_struct);
-    bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
 
     Entity struct_entity = {
         .state = Entity_State_Resolve_Symbols,
@@ -977,9 +976,12 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP
  
     if (onyx_has_errors()) {
         onyx_report_error(pos, "Error in creating polymoprhic struct instantiation here.");
+        bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, NULL);
         return NULL;
     }
 
+    bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
+
     Type* cs_type = type_build_from_ast(context.ast_alloc, (AstType *) concrete_struct);
     cs_type->Struct.poly_sln = NULL;
     bh_arr_new(global_heap_allocator, cs_type->Struct.poly_sln, bh_arr_length(slns));