You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed in issue ohua-dev/ohuac#5 we consider it a good idea not to allow rebinding or shadowing of bindings. These can easily lead to sometimes hard to find bugs, particularly when refactoring. This is made worse by the fact that the ohua dsl is currently untyped and hence it is even less likely that renaming bugs are found.
Proposal
The proposed idea is to add an additional pass over ALang, at the beginning of the compilation and ahead of SSA which is scope-aware and reports rebinding and shadowing as an error to the user.
This is similar to what the Java compiler does for instance.
This would make binding a name, whether as function argument or let, when the same name is already in scope an error.
Examples
let x =()inlet x =()in...
This would be illegal as x is in scope because of the earlier let
let x =()inlet f =\x ->...in...
Also illegal when x is used as a lambda argument the outer x is in scope from the closure.
The same also goes for
let f =\x ->let x =()in...let f =\x ->\x ->...
Legal however would be
let f =\x ->...inlet g =\x ->...in
As closing the fist lambda means x is no longer in scope.
Similarly with
let y = (let x =()in...) inlet x =()in
A point of open discussion would be whether
let x = (let x =()in...)
is legal. We need to decide whether x is in scope for its own binding or not. This is related to the recursion discussion from ohua-dev/ohuac#5.
As discussed in issue ohua-dev/ohuac#5 we consider it a good idea not to allow rebinding or shadowing of bindings. These can easily lead to sometimes hard to find bugs, particularly when refactoring. This is made worse by the fact that the ohua dsl is currently untyped and hence it is even less likely that renaming bugs are found.
Proposal
The proposed idea is to add an additional pass over ALang, at the beginning of the compilation and ahead of SSA which is scope-aware and reports rebinding and shadowing as an error to the user.
This is similar to what the Java compiler does for instance.
This would make binding a name, whether as function argument or let, when the same name is already in scope an error.
Examples
This would be illegal as
x
is in scope because of the earlierlet
Also illegal when
x
is used as a lambda argument the outerx
is in scope from the closure.The same also goes for
Legal however would be
As closing the fist lambda means
x
is no longer in scope.Similarly with
A point of open discussion would be whether
is legal. We need to decide whether
x
is in scope for its own binding or not. This is related to the recursion discussion from ohua-dev/ohuac#5.EDIT: I guess #3 is also relevant here
The text was updated successfully, but these errors were encountered: