Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Disallow shadowing and rebinding #9

Open
JustusAdam opened this issue May 15, 2018 · 0 comments
Open

[Feature] Disallow shadowing and rebinding #9

JustusAdam opened this issue May 15, 2018 · 0 comments

Comments

@JustusAdam
Copy link
Member

JustusAdam commented May 15, 2018

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 = () in
  let x = () in
    ...

This would be illegal as x is in scope because of the earlier let

let x = () in
  let 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 -> ... in
  let g = \x -> ... in

As closing the fist lambda means x is no longer in scope.
Similarly with

let y = (let x = () in ...) in
  let 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.

EDIT: I guess #3 is also relevant here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant