divnix / POP

Pure Object Prototypes
MIT License
21 stars 1 forks source link

Inherited extensions are evaluated twice #2

Closed Pacman99 closed 2 years ago

Pacman99 commented 2 years ago
let
  a = pop { defaults.n = 1; extension = self: super: { n = super.n + 1; }; }
  b = pop { supers = [ a ]; }
in
  b.n

evaluates to 3 when it should be 2

Pacman99 commented 2 years ago

I think the precedence list has duplicated entries of a

fare commented 2 years ago

Diagnosis looks correct... now to find the root cause :-/

fare commented 2 years ago

It looks like on the Nix 2.5.1 that I use, we don't have (no longer have?) O == O where O is an object, which causes the c3 linearization algorithm to malfunction.

fare commented 2 years ago

The algorithm works properly when passed comparable objects such as strings or numbers. But it fails when passed objects. Maybe we could give each object a unique identifier, but doing that in a pure way is a bitch, and doing that by introducing comparable low-level markers that are pure to compare but impure to print would require extending the base language. Or is there a builtin === function?

fare commented 2 years ago

I pushed debugging statements in branch debugMultipleInheritance that demonstrate the issue.