1
0
mirror of https://github.com/nushell/nushell.git synced 2025-08-13 16:37:33 +02:00

Allow int/float to coerce in type checker ()

This commit is contained in:
JT
2022-01-06 07:58:58 +11:00
committed by GitHub
parent 3c2a336ef9
commit cc1ae969fe
2 changed files with 12 additions and 0 deletions
crates/nu-parser/src
src/tests

@ -8,6 +8,8 @@ use nu_protocol::{
pub fn type_compatible(lhs: &Type, rhs: &Type) -> bool {
match (lhs, rhs) {
(Type::List(c), Type::List(d)) => type_compatible(c, d),
(Type::Number, Type::Int) => true,
(Type::Number, Type::Float) => true,
(Type::Unknown, _) => true,
(_, Type::Unknown) => true,
(lhs, rhs) => lhs == rhs,

@ -14,3 +14,13 @@ fn type_in_list_of_this_type() -> TestResult {
fn type_in_list_of_non_this_type() -> TestResult {
fail_test(r#"'hello' in [41 42 43]"#, "mismatched for operation")
}
#[test]
fn number_int() -> TestResult {
run_test(r#"def foo [x:number] { $x }; foo 1"#, "1")
}
#[test]
fn number_float() -> TestResult {
run_test(r#"def foo [x:number] { $x }; foo 1.4"#, "1.4")
}