nix icon indicating copy to clipboard operation
nix copied to clipboard

__curPos can be overwritten without warning, but cannot be used

Open sivizius opened this issue 3 years ago • 2 comments

Describe the bug

__curPos is a useful builtin in get the current position, e.g. for debugging purposes. However, due to its implementation, it can be overwritten without any warning, but can only be used in combination with the keyword inherit. If used directly, the builtin will always be used.

Steps To Reproduce

nix-repl> let __curPos = "Hello World"; in __curPos
{ column = 34; file = "let __curPos = \"Hello World\"; in __curPos"; line = 1; }

Expected behavior

Either a warning/error to prevent overwriting __curPos or, what I prefer, allow overwriting and implement it differently. Btw. the set should include an attribute _type = "position"; or something like that, similar to e.g. derivations.

nix-env --version output

Priorities

Add :+1: to issues you find important.

sivizius avatar Feb 04 '23 18:02 sivizius

It should be documented as a keyword, not a builtin.

roberth avatar Feb 07 '23 14:02 roberth

In 2.18, it really is a keyword and not a variable reference that adheres to scope rules etc.

In the repl, it evaluates to null now, which I'd consider to be a bug.

Welcome to Nix 2.18.1. Type :? for help.

nix-repl> let __curPos = "Hello World"; in __curPos
null

roberth avatar Feb 19 '24 08:02 roberth