what I really was wondering, why this code doesnt work:
var y : Int32 := 10;
var p_y : ^Int32 := $0;
if y = 10 then
begin
var x := 10;
var y := 20; //"Duplicate Variable" it prints
p_y := @y;
writeLn(p_y^);
end;
p_y^ := 30;
writeLn(p_y^);
Actually, it should work, because if-else has their own scope within the stack, so it should actually behave like C-if/else codeblocks and I also read the docs for this, in order not to write this, but I couldnt find this anywhere, so is this by design or maybe a sneaky bug ?
Ah ok, good to know and actually I think this also even better because, consider you have a long calculation going on in the if-block, and do a lot of “complex” stuff with “y” and then you are able to “reuse” y in the parent-scope(out of the if-scope) and you start wondering, why this value didnt change, I think this could happen in a large code base, IMHO
Hmm, this is just a really primitive idea, i know, but couldnt the compiler just check if a pointer gets an adress-assignment within a nested scope, like if -block in a function, and immediately he denies compilation when he sees such constructs, where a locasl variable adress is assgined to a pointer, which itself is “globally”, within a function?
In short: If “x” local, means nested in a new scope, (begin/end) then disallow compilation or such ^^?