poly-struct arguments are query-able from '.' syntax
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 15 Jul 2021 14:04:02 +0000 (09:04 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 15 Jul 2021 14:04:02 +0000 (09:04 -0500)
src/onyxutils.c

index c6ea629b95503f9c8b2c44a02afe03129cae75bb..64c5691c47311773f861db4bd2d1b04d33d9b73f 100644 (file)
@@ -140,8 +140,6 @@ AstNode* symbol_raw_resolve(Scope* start_scope, char* sym) {
         }
     }
 
-    if (res == NULL) return NULL;
-
     return res;
 }
 
@@ -201,7 +199,24 @@ all_types_peeled_off:
 
         case Ast_Kind_Struct_Type: {
             AstStructType* stype = (AstStructType *) node;
-            return symbol_raw_resolve(stype->scope, symbol);
+            AstNode* result = symbol_raw_resolve(stype->scope, symbol);
+
+            if (result == NULL && stype->stcache != NULL) {
+                Type* struct_type = stype->stcache;
+                assert(struct_type->kind == Type_Kind_Struct);
+
+                bh_arr_each(AstPolySolution, sln, struct_type->Struct.poly_sln) {
+                    if (token_text_equals(sln->poly_sym->token, symbol)) {
+                        if (sln->kind == PSK_Type) {
+                            result = (AstNode *) sln->type->ast_type;
+                        } else {
+                            result = (AstNode *) sln->value;
+                        }
+                    }
+                }
+            }
+
+            return result;
         }
 
         case Ast_Kind_Poly_Struct_Type: {