Repository navigation
[parser] Improve type errors for boolean literals - #16408
Conversation
|
Thanks |
|
I still feel it strange to type check boolean values in that place while not doing the same for |
|
@blindFS they are checked, actually, but only for some variations. Which causes errors to diverge depending on capitalization: ~> def test [port: int] {}
~> test NaN
Error: nu::parser::type_mismatch
× Type mismatch.
╭─[entry #8:1:6]
1 │ test NaN
· ─┬─
· ╰── expected int, found float
╰────
~> test nan
Error: nu::parser::parse_mismatch
× Parse mismatch during operation.
╭─[entry #9:1:6]
1 │ test nan
· ─┬─
· ╰── expected int
╰────nushell/crates/nu-parser/src/parser.rs Lines 5222 to 5224 in 751ef6e
nushell/crates/nu-parser/src/parser.rs Lines 1279 to 1285 in 751ef6e But Oh, and I think I found an error |
|
@kaathewisegit Thanks for doing the experiments My main confusion is why we don't put the reserved keyword values check into the |
Currently, strings
trueandfalseare intercepted early in parsing. Previously, if they didn't match the expected shape, the parse error said "expected non-boolean value". This PR changes the message to say "expected ".Because the parsing error requires a
&'static strI had to add ato_str(&self) -> &'static strmethod onSyntaxShape. It's a bit crude for more complex shapes: it simply sayskeyword,list,table, and so on for them, without exposing the underlying structure.Fixes #16406
Release notes summary
Type errors involving boolean literals are now more precise.