field accesses only work on lvals now
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 12 Dec 2020 03:25:29 +0000 (21:25 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 12 Dec 2020 03:26:13 +0000 (21:26 -0600)
This is always how it has worked, now a proper error is actually
reported.

docs/todo
include/onyxastnodes.h
onyx
src/onyxchecker.c

index 5c6c33038413c70221c532098f9ac3d1f8319047..80390be122dee31390681f6e068c3c536bc4d627 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -60,7 +60,7 @@ Language Cohesion:
     [ ] :: should not declare a local variable, just bind a name to an expression.
         They can still be lexically scoped.
 
-    [ ] Currently accessing a field directly on a function call produces invalid
+    [X] Currently accessing a field directly on a function call produces invalid
         WASM code; i.e.  foo().bar; This should at least produce an error until
         the underlying issue is fixed.
 
index 70b192944eddc8777c9b7e191d149466f6ade357..c752c68df9da89bbeca8950cd533978b6717da01 100644 (file)
@@ -854,6 +854,7 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(Type
 // NOTE: Useful inlined functions
 static inline b32 is_lval(AstNode* node) {
     return (node->kind == Ast_Kind_Local)
+        || (node->kind == Ast_Kind_Param)
         || (node->kind == Ast_Kind_Global)
         || (node->kind == Ast_Kind_Dereference)
         || (node->kind == Ast_Kind_Array_Access)
diff --git a/onyx b/onyx
index 9b9eec7bcad59e6b03d35baa93c37b6d28ccad04..25b0aaf11a70d94665bc12adb77f8c336a37fc33 100755 (executable)
Binary files a/onyx and b/onyx differ
index 0226e5a7504ab5e0136ca77259fd1ccaadcde824..e8b0911860fe113c1de04f72bf69cef5f1764658 100644 (file)
@@ -1005,6 +1005,14 @@ b32 check_field_access(AstFieldAccess** pfield) {
         return 1;
     }
 
+    if (!is_lval((AstNode *) field->expr)) {
+        onyx_report_error(field->token->pos,
+            "Cannot access field '%b'. Expression is not an lval.",
+            field->token->text,
+            field->token->length);
+        return 1;
+    }
+
     StructMember smem;
     if (field->token != NULL && field->field == NULL) {
         token_toggle_end(field->token);