-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a subsumption rule between record types and dictionary types #1977
Changes from 3 commits
35ff633
abbbe1f
00a9537
c99634e
bb20fc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2420,7 +2420,39 @@ pub fn subsumption( | |||||
checked: UnifType, | ||||||
) -> Result<(), UnifError> { | ||||||
let inferred_inst = instantiate_foralls(state, &mut ctxt, inferred, ForallInst::UnifVar); | ||||||
checked.unify(inferred_inst, state, &ctxt) | ||||||
match (&inferred_inst, &checked) { | ||||||
( | ||||||
UnifType::Concrete { | ||||||
typ: TypeF::Record(rrows), | ||||||
.. | ||||||
}, | ||||||
UnifType::Concrete { | ||||||
typ: TypeF::Dict { type_fields, .. }, | ||||||
.. | ||||||
}, | ||||||
) => { | ||||||
for row in rrows.iter() { | ||||||
match row { | ||||||
GenericUnifRecordRowsIteratorItem::Row(a) => { | ||||||
subsumption(state, ctxt.clone(), a.typ.clone(), *type_fields.clone())? | ||||||
} | ||||||
GenericUnifRecordRowsIteratorItem::TailUnifVar { id, .. } => state | ||||||
.table | ||||||
.assign_rrows(id, UnifRecordRows::concrete(RecordRowsF::Empty)), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be good to also reproduce the comment that was at the other place where this code was taken from, saying that because we are unifying with a ground type, we don't need to care about level and stuff. Usually |
||||||
GenericUnifRecordRowsIteratorItem::TailConstant(id) => { | ||||||
Err(UnifError::WithConst { | ||||||
var_kind: VarKindDiscriminant::EnumRows, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Copy-paste leftover I guess, but we are unifying record rows, not enum rows 🙂 |
||||||
expected_const_id: id, | ||||||
inferred: checked.clone(), | ||||||
})? | ||||||
} | ||||||
_ => (), | ||||||
} | ||||||
} | ||||||
Ok(()) | ||||||
} | ||||||
(_, _) => checked.unify(inferred_inst, state, &ctxt), | ||||||
} | ||||||
} | ||||||
|
||||||
fn check_field<V: TypecheckVisitor>( | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: in Rust, when you have a match case of the form (that is with only one pattern and a default case)
It's more idiomatic to use an
if-let
. It's exactly the same result but save one level of indentation: