-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Scoping is unintuitive #490
Comments
This is by design IIRC because of some laziness-related properties. (I do agree it's counter-intuitive.) Laziness above refers to evaluation and not the implementors ;-) |
This is by design. It makes most lookups in the presence of |
😦 😦 😦 |
Ah, so |
Is there any action to do here? |
No, we can't change the with scoping rules at this point. And anyway, it would be a bad idea. See here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with#Ambiguity_contra |
Well, that's more of an argument against having/using let lib = something.very.long; in { lib.foo /*etc..*/ } and do it without the scoping ambiguities. Anyway, changing behavior of any currently valid code would need strong arguments. |
No, the Javascript example:
is not a problem with Nix's scoping rules, because |
Using |
- Reorder the lists in asciibetical order; - Use install instead of mkdir + cp; - Use nix functional code construction instead of shell loop code construction; - Get rid of nested `with` in meta + Because `with` itself is an antipattern, as discussed in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Format the code. Also, add myself as maintainer.
- Reorder the lists in asciibetical order; - Use install instead of mkdir + cp; - Use nix functional code construction instead of shell loop code construction; - Get rid of nested `with` in meta + Because `with` itself is an antipattern, as discussed in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Format the code. Also, add myself as maintainer.
- Reorder the lists in asciibetical order; - Use install instead of mkdir + cp; - Use nix functional code construction instead of shell loop code construction; - Get rid of nested `with` in meta + Because `with` itself is an antipattern, as discussed in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Format the code. Also, add myself as maintainer.
- Get rid of nested `with` in meta + Because `with` itself is an antipattern, as explained in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Add meta.longDescription; - Add meta.changelog; - Update meta.maintainers list.
- Get rid of nested `with` in meta + Because `with` itself is an antipattern, as explained in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Add meta.longDescription; - Add meta.changelog; - Update meta.maintainers list.
- Get rid of nested `with` in meta + Because `with` itself is an antipattern, as explained in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Add meta.longDescription; - Add meta.changelog; - Update meta.maintainers list.
- Get rid of nested `with` in meta + Because `with` itself is an antipattern, as explained in https://nix.dev/anti-patterns/language#with-attrset-expression + Because nested `with` has unintuitive behavior, as shown in NixOS/nix#490 - Add meta.longDescription; - Add meta.changelog; - Update meta.maintainers list.
As related in https://nix.dev/anti-patterns/language#with-attrset-expression: - Static analysis can’t reason about the code, because it would have to actually evaluate this file to see what variables are in scope; - As soon as there are two with used, it’s not clear anymore from which the variables are coming from; - Scoping rules around with are not intuitive. Examples: - NixOS/nix#490 - pikajude@eea78e5
As related in https://nix.dev/anti-patterns/language#with-attrset-expression: - Static analysis can’t reason about the code, because it would have to actually evaluate this file to see what variables are in scope; - As soon as there are two with used, it’s not clear anymore from which the variables are coming from; - Scoping rules around with are not intuitive. Examples: - NixOS/nix#490 - pikajude@eea78e5
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/removing-most-uses-of-top-level-with/41233/1 |
Provide diagnostic mentioned in NixOS/nix#490 ![image](https://github.com/nix-community/nixd/assets/36667224/4db9ed38-e07e-4dc3-b3e5-9d5943aaa880)
Is this by design? It seems weird.
Contrarily,
let a = "outer"; in let a = "inner"; in a
returns"inner"
.The text was updated successfully, but these errors were encountered: