From: Brendan Hansen Date: Sat, 12 Dec 2020 03:25:29 +0000 (-0600) Subject: field accesses only work on lvals now X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c759c935b71ff1d1bda6b86a68a3138b04ad17cd;p=onyx.git field accesses only work on lvals now This is always how it has worked, now a proper error is actually reported. --- diff --git a/docs/todo b/docs/todo index 5c6c3303..80390be1 100644 --- 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. diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 70b19294..c752c68d 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -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 9b9eec7b..25b0aaf1 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 0226e5a7..e8b09118 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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);