mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
parse default optional expressions in pattern matches
This commit is contained in:
parent
6d40de7430
commit
d779e68773
6 changed files with 209 additions and 26 deletions
|
@ -3011,4 +3011,68 @@ mod solve_uniq_expr {
|
|||
"Attr * (Attr Shared (Num (Attr Shared *)) -> Attr * (Num (Attr * *)))",
|
||||
);
|
||||
}
|
||||
|
||||
// OPTIONAL RECORD FIELDS
|
||||
|
||||
#[test]
|
||||
fn optional_field_unifies_with_missing() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
negatePoint : { x : Int, y : Int, z ? Num c } -> { x : Int, y : Int, z : Num c }
|
||||
|
||||
negatePoint { x: 1, y: 2 }
|
||||
"#
|
||||
),
|
||||
"Attr * { x : (Attr * Int), y : (Attr * Int), z : (Attr * (Num (Attr * c))) }",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_optional_field_unifies_with_missing() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
negatePoint : { x : Int, y : Int, z ? Num c }r -> { x : Int, y : Int, z : Num c }r
|
||||
|
||||
a = negatePoint { x: 1, y: 2 }
|
||||
b = negatePoint { x: 1, y: 2, blah : "hi" }
|
||||
|
||||
{ a, b }
|
||||
"#
|
||||
),
|
||||
"Attr * { a : (Attr * { x : (Attr * Int), y : (Attr * Int), z : (Attr * (Num (Attr * c))) }), b : (Attr * { blah : (Attr * Str), x : (Attr * Int), y : (Attr * Int), z : (Attr * (Num (Attr * c))) }) }"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optional_field_unifies_with_present() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
negatePoint : { x : Num a, y : Num b, z ? c } -> { x : Num a, y : Num b, z : c }
|
||||
|
||||
negatePoint { x: 1, y: 2.1, z: 0x3 }
|
||||
"#
|
||||
),
|
||||
"Attr * { x : (Attr * (Num (Attr * a))), y : (Attr * Float), z : (Attr * Int) }",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_optional_field_unifies_with_present() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
negatePoint : { x : Num a, y : Num b, z ? c }r -> { x : Num a, y : Num b, z : c }r
|
||||
|
||||
a = negatePoint { x: 1, y: 2.1 }
|
||||
b = negatePoint { x: 1, y: 2.1, blah : "hi" }
|
||||
|
||||
{ a, b }
|
||||
"#
|
||||
),
|
||||
"Attr * { a : (Attr * { x : (Attr * (Num (Attr * a))), y : (Attr * Float), z : (Attr * c) }), b : (Attr * { blah : (Attr * Str), x : (Attr * (Num (Attr * a))), y : (Attr * Float), z : (Attr * c) }) }"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue