mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Fix default argument value type checking (#10460)
# Description Fix type checking in arguments default values not adhering to subtyping rules Currently following examples produce a parse error: ```nu def test [ --qwe: record<a: int> = {a: 1 b: 1} ] { } def test [ --qwe: list<any> = [ 1 2 3 ] ] { } ``` despite types matching. Type equality check is replaced with subtyping check and everything parses fine: # User-Facing Changes Default values of flag arguments type checking behavior is in line with `let` statements
This commit is contained in:
parent
65e2733571
commit
e96039fb1b
@ -3838,7 +3838,7 @@ pub fn parse_signature_helper(working_set: &mut StateWorkingSet, span: Span) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t => {
|
t => {
|
||||||
if t != &expression_ty {
|
if !type_compatible(t, &expression_ty) {
|
||||||
working_set.error(
|
working_set.error(
|
||||||
ParseError::AssignmentMismatch(
|
ParseError::AssignmentMismatch(
|
||||||
"Default value is the wrong type"
|
"Default value is the wrong type"
|
||||||
|
@ -247,6 +247,12 @@ fn parse_long_duration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
#[case("def test [ --a: any = 32 ] {}")]
|
||||||
|
#[case("def test [ --a: number = 32 ] {}")]
|
||||||
|
#[case("def test [ --a: number = 32.0 ] {}")]
|
||||||
|
#[case("def test [ --a: list<any> = [ 1 2 3 ] ] {}")]
|
||||||
|
#[case("def test [ --a: record<a: int b: string> = { a: 32 b: 'qwe' c: 'wqe' } ] {}")]
|
||||||
|
#[case("def test [ --a: record<a: any b: any> = { a: 32 b: 'qwe'} ] {}")]
|
||||||
#[case("def test []: int -> int { 1 }")]
|
#[case("def test []: int -> int { 1 }")]
|
||||||
#[case("def test []: string -> string { 'qwe' }")]
|
#[case("def test []: string -> string { 'qwe' }")]
|
||||||
#[case("def test []: nothing -> nothing { null }")]
|
#[case("def test []: nothing -> nothing { null }")]
|
||||||
|
Loading…
Reference in New Issue
Block a user