tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.23k stars 85 forks source link

`std.record.get_or` is not working as expected #1945

Closed penglei closed 3 weeks ago

penglei commented 3 weeks ago

Describe the bug

❯ nickel repl
nickel> std.record.get_or "a" true {}
true

nickel> std.record.get_or "a" true {a}
error: missing definition for `a`
     ┌─ <repl-input-1>:1:28
     │
   1 │ std.record.get_or "a" true {a}
     │                            --- in this record
     │
     ┌─ <stdlib/std.ncl>:2191:11
     │
2191 │           record."%{field}"
     │           ----------------- accessed here

I think std.record.get_or "a" true {a} should also yield true.

yannham commented 3 weeks ago

Hmm, field without definitions are a bit in a grey area, but in the end it makes sense that as a user you don't care about those subtleties, what you want is to just get a definite value no matter what's in the record.

Giving a default value when the field is there but doesn't have a value is also the current behavior of the ? operator in patterns, so it's one more reason to be consistent and apply that behavior to get_or as well.