mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
preparations for unifying optional fields
This commit is contained in:
parent
13b3748996
commit
d47abfb3a6
3 changed files with 28 additions and 17 deletions
|
@ -47,6 +47,15 @@ pub enum RecordFieldLabel {
|
|||
Optional(Lowercase),
|
||||
}
|
||||
|
||||
impl Into<Lowercase> for RecordFieldLabel {
|
||||
fn into(self) -> Lowercase {
|
||||
match self {
|
||||
RecordFieldLabel::Required(label) => label,
|
||||
RecordFieldLabel::Optional(label) => label,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for RecordFieldLabel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
|
|
@ -173,6 +173,7 @@ fn unify_record(
|
|||
rec1: RecordStructure,
|
||||
rec2: RecordStructure,
|
||||
) {
|
||||
// This is a bit more complicated because of optional fields
|
||||
let fields1 = rec1.fields;
|
||||
let fields2 = rec2.fields;
|
||||
let shared_fields = fields1
|
||||
|
|
|
@ -980,6 +980,22 @@ mod test_infer {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_type_annotation() {
|
||||
// check that a closed record remains closed
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
foo : { x : custom } -> custom
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo
|
||||
"#
|
||||
),
|
||||
"{ x : custom } -> custom",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optional_field() {
|
||||
infer_eq(
|
||||
|
@ -988,25 +1004,10 @@ mod test_infer {
|
|||
foo : { x? : Int } -> Int
|
||||
foo = \_ -> 42
|
||||
|
||||
foo {}
|
||||
foo
|
||||
"#
|
||||
),
|
||||
"Int",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_type_annotation() {
|
||||
infer_eq(
|
||||
indoc!(
|
||||
r#"
|
||||
foo : { x : custom } -> custom
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo
|
||||
"#
|
||||
),
|
||||
"{ x : custom } -> custom",
|
||||
"{ x? : Int } -> Int",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue