Closed gergelyk closed 2 years ago
Good catch. Notice the difference:
0.000245 elvish> put $f~
▶ <builtin nop~>
0.000193 elvish> put $nop~
▶ <builtin nop>
And compare with this formulation:
0.000392 elvish> var n~ = $nop~
0.000158 elvish> put $n~
▶ <builtin nop>
0.000175 elvish> is $n~ $nop~
▶ $true
FYI, I have a fix for this but need to sleep on it before creating a pull-request. My fix addresses this specific situation but breaks two existing unit tests: TestAddVar
and TestAddVars
. My change creates an actual alias to the builtin nop
command rather than using the equivalent of fn nop { }
(which is why the is $f~ $nop~
test fails). I need to look at what those tests are doing to understand why they are failing with my change.
My simple fix for this issue addresses this narrow issue but is incorrect. It simply assigned the read-only $nop~
value as the default value of a command variable. Which is why it broke the TestAddVar
and TestAddVars
unit tests. A proper fix needs to make var f~
and var f~ = $nop~
equivalent.
According to https://elv.sh/ref/language.html#variable-suffix Variables with
~
suffix are initialized tonop
. As far as I understand, it should be accessible through$nop~
, but it seems not. As we can see below, variable was initialized tonop~
instead ofnop
. Corresponding$nop~~
doesn't exist.