Skip to content

Function equality is broken #3371

Open
Open
@puckipedia

Description

As foretold by the code,

/* Functions are incomparable. */

And this seems to be true. If we try to evaluate this:

let lambda = (a: a); in lambda == lambda

We get a nice false result, as expected. But, what if ... we put the lambda in an attrset?

let lambda = (a: a); in { inherit lambda; } == { inherit lambda; }

Now, all of a sudden, the two attrsets are equal! But this is impossible, as functions are incomparable!

The reason for this is a 2010 hack added to support "some old broken code that relies on pointer equality":

nix/src/libexpr/eval.cc

Lines 1689 to 1692 in 2e953b5

/* !!! Hack to support some old broken code that relies on pointer
equality tests between sets. (Specifically, builderDefs calls
uniqList on a list of sets.) Will remove this eventually. */
if (&v1 == &v2) return true;

Metadata

Assignees

No one assigned

    Labels

    breakingChanges we can't make without breaking old expressions, changing hashes, etcbuglanguageThe Nix expression language; parser, interpreter, primops, evaluation, etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions