mrozycki / space-lang

What if identifiers could be anything? Langjam submission
6 stars 0 forks source link

Idents in parent scopes are not checked for ambiguity with assignments to idents in child scopes #7

Open camc opened 3 years ago

camc commented 3 years ago

The following should be an error:

let ia := 1;
if ia == 1 {
    let ib := 2;
    i := 3;
    println (ia);
    println (ib);
}
meithecatte commented 3 years ago

what should this do, then?

let ab := 1;
if ab == 1 {
    let a := 2;
    a := 3;
    println(a);
}
println(ab);
camc commented 3 years ago

maybe referring to an ident directly (not a prefix) should be allowed?

meithecatte commented 3 years ago

IMHO your example is just a consequence of shadowing. If we want to change this, there are some thorny edge-cases. For example, what if we shadow the variable like this?

let ab := 1;
if ab == 1 {
    let ab := 2;
    a := 3;
    println(ab);
}
println(ab);
mrozycki commented 3 years ago

Shadowing aside, it is possible to have an identifier that is a prefix of another identifier:

let ab := 1;
let a := 3;
print(a); ???;

I think an exact match should win in this case.

This also means we might need to trim identifiers. Right now let a := 1; produces an identifier a, which does not exact match to a from print(a).

camc commented 3 years ago

I didn't know we allowed shadowing :laughing:

camc commented 3 years ago

This also means we might need to trim identifiers. Right now let a := 1; produces an identifier a , which does not exact match to a from print(a).

I think this is no longer the case, I started trimming them in the lexer