polymorphic struct types can have members accessed
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 29 Jan 2021 17:53:19 +0000 (11:53 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 29 Jan 2021 17:53:19 +0000 (11:53 -0600)
bin/onyx
onyx.exe
src/onyxsymres.c

index 864a538d8e8e7cd5dfab3fbabf4ac2fffe07e1e8..039edd7eba7da4544f5640718963d212567e2d91 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 8ef49cd8a7413282c5fbf49ea4fbc0202955e959..61ba581eef1e70fa0ab6e20e5ff771fef116c871 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index cedba6232e6c5f82425dc595a4dfcba9347d429e..77c0047e69a5b4a63eb24e17c9bd519a4d22faaa 100644 (file)
@@ -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) {