From 515d886a56d977c06bff80684672a6d63975ba89 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 15 Jul 2021 09:04:02 -0500 Subject: [PATCH] poly-struct arguments are query-able from '.' syntax --- src/onyxutils.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/onyxutils.c b/src/onyxutils.c index c6ea629b..64c5691c 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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: { -- 2.25.1