preparations for unifying optional fields

This commit is contained in:
Folkert 2019-12-30 16:52:57 +01:00
parent 13b3748996
commit d47abfb3a6
3 changed files with 28 additions and 17 deletions

View file

@ -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 {

View file

@ -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

View file

@ -980,23 +980,9 @@ mod test_infer {
);
}
#[test]
fn optional_field() {
infer_eq(
indoc!(
r#"
foo : { x? : Int } -> Int
foo = \_ -> 42
foo {}
"#
),
"Int",
);
}
#[test]
fn record_type_annotation() {
// check that a closed record remains closed
infer_eq(
indoc!(
r#"
@ -1009,4 +995,19 @@ mod test_infer {
"{ x : custom } -> custom",
);
}
#[test]
fn optional_field() {
infer_eq(
indoc!(
r#"
foo : { x? : Int } -> Int
foo = \_ -> 42
foo
"#
),
"{ x? : Int } -> Int",
);
}
}