From 8dc246166a007c2815f93ff6db535a660b05431c Mon Sep 17 00:00:00 2001
From: A404M <ahmadmahmoudiprogrammer@gmail.com>
Date: Mon, 9 Jun 2025 18:56:19 +0330
Subject: fix assigning to dereference access in a chain

---
 src/runner/runner.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

(limited to 'src/runner/runner.c')

diff --git a/src/runner/runner.c b/src/runner/runner.c
index ef363fe..ab4e9b5 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -1676,13 +1676,12 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
   }
   case AST_TREE_TOKEN_OPERATOR_DEREFERENCE: {
     AstTreeSingleChild *metadata = expr->metadata;
-    AstTree *operand = runExpression(metadata, scope, shouldRet, false,
+    AstTree *operand = runExpression(metadata, scope, shouldRet, true,
                                      isComptime, breakCount, shouldContinue);
     if (discontinue(*shouldRet, *breakCount)) {
       return operand;
     }
-    if (operand->token == AST_TREE_TOKEN_RAW_VALUE ||
-        operand->token == AST_TREE_TOKEN_RAW_VALUE_NOT_OWNED) {
+    if (operand->token == AST_TREE_TOKEN_RAW_VALUE) {
       if (operand->type->token != AST_TREE_TOKEN_OPERATOR_POINTER) {
         printLog("%s", AST_TREE_TOKEN_STRINGS[operand->type->token]);
         UNREACHABLE;
@@ -1694,6 +1693,16 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
       memcpy(value, *(void **)operand->metadata, size);
       astTreeDelete(operand);
       return newAstTree(AST_TREE_TOKEN_RAW_VALUE, value, type, NULL, NULL);
+    } else if (operand->token == AST_TREE_TOKEN_RAW_VALUE_NOT_OWNED) {
+      if (operand->type->token != AST_TREE_TOKEN_OPERATOR_POINTER) {
+        printLog("%s", AST_TREE_TOKEN_STRINGS[operand->type->token]);
+        UNREACHABLE;
+      }
+      AstTree *type =
+          copyAstTree((AstTreeSingleChild *)operand->type->metadata);
+      AstTreeRawValue *value = *(void **)operand->metadata;
+      astTreeDelete(operand);
+      return newAstTree(AST_TREE_TOKEN_RAW_VALUE_NOT_OWNED, value, type, NULL, NULL);
     } else if (operand->token == AST_TREE_TOKEN_VARIABLE) {
       AstTree *ret;
       if (isLeft) {
-- 
cgit v1.2.3