mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Allow int/float to coerce in type checker (#679)
This commit is contained in:
parent
3c2a336ef9
commit
cc1ae969fe
2 changed files with 12 additions and 0 deletions
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue