Skip to content

Commit 4c2e8ad

Browse files
authored
Fix change changing value even if out of scope (#19)
2 parents f0f87ee + 6b25002 commit 4c2e8ad

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

.github/workflows/build_test_check.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ name: Build/Test Check
22

33
on:
44
push:
5+
branches:
6+
- main
57
paths:
68
- 'src/**'
79
- 'include/**'
810
- '.github/workflows/build_test_check.yml'
911
pull_request:
10-
branches: [ "main" ]
12+
branches:
13+
- main
1114
paths:
1215
- 'src/**'
1316
- 'include/**'

bin/test.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a = 0
2+
def test():
3+
while a < 5:
4+
a += 1
5+
6+
test()
7+
print(a)

bin/test.w

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def int fibonacci with int n
2-
if n less 2
3-
return n
4-
else
5-
call fibonacci with n minus 1 store result1
6-
call fibonacci with n minus 2 store result2
7-
return result1 plus result2
8-
endif
1+
int a assign 0
2+
def null test
3+
infloop
4+
if a gequal 5
5+
break
6+
endif
7+
change a to a plus 1
8+
endinf
99
enddef
1010

11-
call fibonacci with 10 store result
12-
print result
11+
call test
12+
print a

bin/word.exe

0 Bytes
Binary file not shown.

src/interpreter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ void *execute(list *parsed_code, Scope *scope, W_Type return_type, bool destroy_
10991099
fprintf(stderr, "Error: Expected variable name after keyword 'change', got '%s', line: %d\n", word->value, word->line);
11001100
exit(1);
11011101
}
1102-
W_Var *var = get_var(scope, word->value);
1102+
W_Var *var = w_dict_get(scope->vars, word->value); //get local variable
11031103
if (var == NULL) {
11041104
fprintf(stderr, "Error: Variable '%s' does not exist, line: %d\n", word->value, word->line);
11051105
exit(1);

0 commit comments

Comments
 (0)