divnix / POP

Pure Object Prototypes
MIT License
20 stars 1 forks source link

Supers are not lazily evaluated #11

Open Pacman99 opened 1 year ago

Pacman99 commented 1 year ago
nix-repl> pop.lib.pop { supers = [ { a = throw "err"; b = 5; } ]; }
error: err

An attribute in a pop containing an error shouldn't error out the entire pop. Other attributes should still be accessible even if one attribute errors out.

The following code should print out 5, but it would just error out now.

p = pop.lib.pop { supers = [ { a = throw "err"; b = 5; } ]; }
p.b

cc @fare

fare commented 1 year ago

That sounds like a bug indeed: the list of supers should be eagerly evaluated to resolve the multiple inheritance hierarchy, but the fields of the super itself shouldn't. Maybe the bug though isn't in the super handling, but in the casting of prototype-less record to pop prototype? Even then that would be a bug, but a different one.

Pacman99 commented 1 year ago

Maybe the bug though isn't in the super handling, but in the casting of prototype-less record to pop prototype?

I dont think so, I just used the plain attribute set as an example, but it happens even if that attrset was wrapped in a kPop.

pop.lib.pop { supers = [ (kPop { a = throw "err"; b = 5; }) ]; }

Also errors out.

GTrunSec commented 1 year ago

@fare Are there any inquiries pertaining to this matter? I also got the same problem when I trying embed POP into my instance. Thanks

Pacman99 commented 1 year ago

I opened this https://github.com/NixOS/nix/issues/8364

fare commented 10 months ago

https://twitter.com/Ngnghm/status/1717684526720094339

Lacking the ability to compare structures or functions by pointer identity, or system-provided nonces as identity tags, the only reliable solution is user-provided labels with some naming conventions to retrieve some modularity.

fare commented 9 months ago

Akshully, we might be able to do proper pointer equality: https://code.tvl.fyi/about/tvix/docs/value-pointer-equality.md

Pacman99 commented 9 months ago

Yeah I just saw that thread! I might give that a try to see if we can fix this issue. I tried something similar with lists which sometimes worked, so hopefully this trick will work fully.

fare commented 9 months ago

Note that one part of the problem is ensuring that true is returned when the two are pointer-equal, the other part of the problem is ensuring that false is returned when they are not, instead of an error being thrown or an infinite branch taken.