From: Brendan Hansen Date: Fri, 29 Jan 2021 17:53:19 +0000 (-0600) Subject: polymorphic struct types can have members accessed X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e1c780933efa627649d0dcb81c4593ce687a9a0c;p=onyx.git polymorphic struct types can have members accessed --- diff --git a/bin/onyx b/bin/onyx index 864a538d..039edd7e 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index 8ef49cd8..61ba581e 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxsymres.c b/src/onyxsymres.c index cedba623..77c0047e 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -280,6 +280,11 @@ static void symres_field_access(AstFieldAccess** fa) { symres_expression(&(*fa)->expr); if ((*fa)->expr == NULL) return; + // CLEANUP: There are way to many cases here that a too similar. + // It should be easy to clean all of these up. Also, I think that when + // that happens, it might be even easier to allow for 'use'ing members + // that are pointers to structures. + if ((*fa)->expr->kind == Ast_Kind_Package) { AstPackage* package = (AstPackage *) (*fa)->expr; AstNode* n = symbol_resolve(package->package->scope, (*fa)->token); @@ -309,6 +314,16 @@ static void symres_field_access(AstFieldAccess** fa) { return; } } + + if ((*fa)->expr->kind == Ast_Kind_Poly_Struct_Type) { + AstStructType* stype = ((AstPolyStructType *) (*fa)->expr)->base_struct; + AstNode* n = symbol_resolve(stype->scope, (*fa)->token); + if (n) { + // Note: not field access + *fa = (AstFieldAccess *) n; + return; + } + } } static void symres_compound(AstCompound* compound) {