mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 12:44:17 +02:00
improve subtyping (#9614)
# Description the current subtyping rule needs you to define the record entries in the same order as declared in the annotation. this pr improves that now ```nushell { name: 'Him', age: 12 } # , { age: 100, name: 'It' } # and { name: 'Red', age: 69, height: "5-8" } # will all match record<name: string, age: int> # previously only the first one would match ``` however, something like ```nushell { name: 'Her' } # will not # and { name: 'Car', wheels: 5 } ``` EDIT: applied JT's suggestion
This commit is contained in:
@@ -59,3 +59,30 @@ fn block_not_first_class_let() -> TestResult {
|
||||
"Blocks are not support as first-class values",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_subtyping() -> TestResult {
|
||||
run_test(
|
||||
"def test [rec: record<name: string, age: int>] { $rec | describe };
|
||||
test { age: 4, name: 'John' }",
|
||||
"record<age: int, name: string>",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_subtyping_2() -> TestResult {
|
||||
run_test(
|
||||
"def test [rec: record<name: string, age: int>] { $rec | describe };
|
||||
test { age: 4, name: 'John', height: '5-9' }",
|
||||
"record<age: int, name: string, height: string>",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_subtyping_3() -> TestResult {
|
||||
fail_test(
|
||||
"def test [rec: record<name: string, age: int>] { $rec | describe };
|
||||
test { name: 'Nu' }",
|
||||
"expected",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user