wiz-lang / wiz

A high-level assembly language for writing homebrew software and games on retro console platforms.
http://wiz-lang.org/
Other
409 stars 40 forks source link

wiz allows inline for iterator to be overridden #71

Closed undisbeliever closed 5 years ago

undisbeliever commented 5 years ago

The following code should cause wiz to fail with a redefinition of symbol error. Instead it allows the dupe variable to be overridden.

// SYSTEM  all

bank code @ 0x8000 : [constdata;  0x8000];

in code {

func test() {
    inline for let dupe in 1 .. 3 {     // REFERENCE
        let constant0 = 1;
        let dupe = 0;                   // ERROR
        let constant1 = 1;

        a = dupe;
    }
}

}
failure/duplicate_let_inline_for.wiz: FAILED
    > ../bin/wiz --system 6502 -o obj/duplicate_let_inline_for.6502.bin failure/duplicate_let_inline_for.wiz
    wiz returned EXIT_SUCCESS in an error test
`--> ../bin/wiz --system 6502 -o obj/duplicate_let_inline_for.6502.bin failure/duplicate_let_inline_for.wiz
* wiz: version 0.1.2 (alpha)
>> Parsing...
>> Compiling...
>> Writing ROM...
>> Wrote to "obj/duplicate_let_inline_for.6502.bin".
* wiz: Done.
.-(~/repo/snes/wiz/tests)----------------------------------------------------------------------(dev@deadlocked)-
`--> r2 -a6502 -m0x8000 obj/duplicate_let_inline_for.6502.bin 
WARNING: using oba to load the syminfo from different mapaddress.
TODO: Must use the API instead of running commands to speedup loading times.
 -- ESIL: The Aftersleep
[0x00008000]> pd
            0x00008000      a900           lda #0x00
            0x00008002      a900           lda #0x00
            0x00008004      a900           lda #0x00
            0x00008006      60             rts
Bananattack commented 5 years ago

Hmm.

This may seem counter-intuitive, but shadowing is permitted by the language in any new lexical scope introduced. The body of the inline for is one scope lower than the scope where the iterator is introduced, which is also one scope lower than the function body. The dupe declared inside the block will shadow the dupe declared as the iterator, but it is not an error given the way lexical scoping works in Wiz. I don't think this is a bug.