hedyorg / hedy

Hedy is a gradual programming language to teach children programming. Gradual languages use different language levels, where each level adds new concepts and syntactic complexity. At the end of the Hedy level sequence, kids master a subset of syntactically valid Python.
https://www.hedy.org
European Union Public License 1.2
1.33k stars 289 forks source link

🪲 Variable access before definition error raised incorrectly #5728

Closed boryanagoncharenko closed 1 month ago

boryanagoncharenko commented 2 months ago

Describe the bug In some cases a command could consider an argument either as a variable, if such is defined, or a literal string. If a variable is defined and if is accessed before its definition, an error is raised. The access-before-definition check uses only line numbers. As a result, the following snippet produces an error while it should not.

Paste the Hedy code & level Level 12:

define turn
    if x is pressed
        print 'good'
    else
        print 'bad'

print 'Start'
call turn
x is 1 + 1
print x
print 'End'

The access-before-definition check should take into account that functions use another scope.

boryanagoncharenko commented 2 months ago

This issue is tightly-coupled to #5749