mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +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),
|
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 {
|
impl fmt::Debug for RecordFieldLabel {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -173,6 +173,7 @@ fn unify_record(
|
||||||
rec1: RecordStructure,
|
rec1: RecordStructure,
|
||||||
rec2: RecordStructure,
|
rec2: RecordStructure,
|
||||||
) {
|
) {
|
||||||
|
// This is a bit more complicated because of optional fields
|
||||||
let fields1 = rec1.fields;
|
let fields1 = rec1.fields;
|
||||||
let fields2 = rec2.fields;
|
let fields2 = rec2.fields;
|
||||||
let shared_fields = fields1
|
let shared_fields = fields1
|
||||||
|
|
|
@ -980,23 +980,9 @@ mod test_infer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn optional_field() {
|
|
||||||
infer_eq(
|
|
||||||
indoc!(
|
|
||||||
r#"
|
|
||||||
foo : { x? : Int } -> Int
|
|
||||||
foo = \_ -> 42
|
|
||||||
|
|
||||||
foo {}
|
|
||||||
"#
|
|
||||||
),
|
|
||||||
"Int",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn record_type_annotation() {
|
fn record_type_annotation() {
|
||||||
|
// check that a closed record remains closed
|
||||||
infer_eq(
|
infer_eq(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
|
@ -1009,4 +995,19 @@ mod test_infer {
|
||||||
"{ x : custom } -> custom",
|
"{ x : custom } -> custom",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn optional_field() {
|
||||||
|
infer_eq(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
foo : { x? : Int } -> Int
|
||||||
|
foo = \_ -> 42
|
||||||
|
|
||||||
|
foo
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
"{ x? : Int } -> Int",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue