-
Notifications
You must be signed in to change notification settings - Fork 21
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
Better sort checking for constructors #895
Comments
Hey @nilehmann - I'm interested in taking a stab at this but I'm not really sure where to start. I'm assuming that this will happen when checking constructor's in I would imagine we need a case for when the expected sort is an inferred sort (after trying to resolve params)? i.e. something like: if let rty::Sort::App(rty::SortCtor::Adt(sort_def), sort_args) = expected {
let expected_def_id = sort_def.did();
if let Some(path) = path {
let path_def_id = match path.res {
ExprRes::Struct(def_id) | ExprRes::Enum(def_id) => def_id,
_ => span_bug!(expr.span, "unexpected path in constructor"),
};
if path_def_id != expected_def_id {
return Err(self.emit_err(errors::SortMismatchFoundOmitted::new(
path.span,
expected.clone(),
)));
}
} else {
self.wfckresults
.record_ctors_mut()
.insert(expr.fhir_id, sort_def.did());
}
self.check_field_exprs(expr.span, sort_def, sort_args, field_exprs, spread, expected)?;
Ok(())
} else if /* snip - expected is an inferred sort */ {
// Stuff above
} else {
Err(self.emit_err(errors::UnexpectedConstructor::new(expr.span, expected)))
} is that right? |
This need a bit more design. We should meet. I'd also like to get @ranjitjhala input. |
Cool - I'll be in today if you want to chat. |
I'm around till noon at least. |
Right now, the following fails:
Result:
A nice solution for this would be (from @nilehmann):
The nice solution for this problem is whenever we check
Range { ... }
against a sorts
we unify it againstRange<?1s>
(for a fresh ?1s). And then check fields assuming?1s
. Ifs
isRange<int>
we will learnRange<?1s> = Range<int> ==> ?1s = int
and consequently check fields against int. Ifs
is?0s
we only learn?0s = Range<?1s>
and will check fields against?1s
.The text was updated successfully, but these errors were encountered: