nix-community / nixd

Nix language server, based on nix libraries [maintainer=@inclyc,@Aleksanaa]
https://github.com/nix-community/nixd
GNU Lesser General Public License v3.0
923 stars 31 forks source link

False positive of sema-unused-def-lambda-noarg-formal #589

Closed rome-user closed 3 months ago

rome-user commented 3 months ago

Describe the bug See the following example

# flake.nix
{
  outputs = { self }: { }
}

I get a warning that the variable self is unused, but if I delete self, I get the following error

$ nix flake check
error:
       … in the left operand of the update (//) operator
         at «nix-internal»/call-flake.nix:69:13:
           68|             # This is shadowed in the next //
           69|             // sourceInfo
             |             ^
           70|             // {

       … from call site
         at «nix-internal»/call-flake.nix:60:21:
           59|
           60|           outputs = flake.outputs (inputs // { self = result; });
             |                     ^
           61|

       error: function 'outputs' called with unexpected argument 'self'
       at /nix/store/bpk3szvancg4lxzpd8sg0f09bsyz0m9m-source/flake.nix:2:13:
            1| {
            2|   outputs = { }: { };
             |             ^
            3| }
inclyc commented 3 months ago

but if I delete self,

Generally there are no way to remove any formal (e.g. a in { a }: b) without potentially breaking the language semantics.

In this case, self can be removed, but must have ... to accept the self formal. That is, the safe way to avoid ``unused-def'' is:

- { self }: { }
+ { ... }: { }

Although the semantics of ... is different from just using self.

rome-user commented 3 months ago

Thanks! This solves my problem