mirror of
https://github.com/nushell/nushell.git
synced 2024-11-08 01:24:38 +01:00
Allow int/float to coerce in type checker (#679)
This commit is contained in:
parent
3c2a336ef9
commit
cc1ae969fe
@ -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 New Issue
Block a user