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

Capability checking does not respect name shadowing #389

Closed
byorgey opened this issue Jun 12, 2022 · 2 comments · Fixed by #390
Closed

Capability checking does not respect name shadowing #389

byorgey opened this issue Jun 12, 2022 · 2 comments · Fixed by #390
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. L-Capability checking Capability checking determines which capabilities are required by a given piece of code. S-Critical This is an issue that seriously affects playability or user experience.

Comments

@byorgey
Copy link
Member

byorgey commented Jun 12, 2022

Describe the bug
If a lambda happens to shadow a name which is already defined, everything works as it should except that capability checking will attribute the capabilities needed for the existing definition to any uses of the name inside the lambda, even though those uses of the name should refer to the lambda binder, which shadows the existing definition.

To reproduce
Start a new classic mode game. Then type at the REPL:

def foo : int = 1 + 2 end
def bar : dir -> cmd () = \foo. turn foo end
build {bar left}

You will get an error like build: this would require installing devices you don't have: lambda and calculator.

Expected behavior
Getting an error about lambda is expected. However, the error about calculator is unexpected, since the definition of bar neither directly nor indirectly uses any arithmetic. In particular it does not refer to foo : int.

Additional context
I checked and #373 still has the same issue, it just formats the error message differently. This is expected since the error probably has to do with the capability checker, which #373 did not change.

Marking this as 'Critical' since if you run into this it is very mysterious and hard to figure out what is wrong. It could also completely block you in a situation where you should have the proper devices but the system is telling you that you don't. I ran into this during a playthrough and was completely stumped for a little while.

@byorgey byorgey added Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. S-Critical This is an issue that seriously affects playability or user experience. L-Capability checking Capability checking determines which capabilities are required by a given piece of code. labels Jun 12, 2022
@byorgey
Copy link
Member Author

byorgey commented Jun 12, 2022

A similar issue arises with let, e.g.

def foo : int = 1 + 2 end
def bar = let foo = left in turn foo end
build {bar}

leads to an error about dictionary and calculator.

@byorgey
Copy link
Member Author

byorgey commented Jun 12, 2022

And one more, given the same definition of foo:

def bar3 = foo <- grab; give base foo end
build {bar3}

also gives an error about calculator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. L-Capability checking Capability checking determines which capabilities are required by a given piece of code. S-Critical This is an issue that seriously affects playability or user experience.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant