When storing variables, merge them directly with the target rather than unifying

When we unify two variables that end up merged, the rank of the
resulting content is the lower of the two variables being merged. But
during storage, we really do mean, take the target descriptor of the
type we're merging against, and don't try to lower to a
possibly-generalized rank! This fixes a couple bugs I didn't even
realize were present!
This commit is contained in:
Ayaz Hafiz 2022-07-29 14:53:14 -04:00
parent 5f115685e4
commit 4657a957f7
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 106 additions and 59 deletions

View file

@ -422,12 +422,13 @@ pub fn constrain_expr(
constraints.lookup(*symbol, expected, region)
}
&AbilityMember(symbol, specialization_id, specialization_var) => {
// make lookup constraint to lookup this symbol's type in the environment
let store_expected = constraints.equal_types_var(
// Save the expectation in the `specialization_var` so we know what to specialize, then
// lookup the member in the environment.
let store_expected = constraints.store(
expected.get_type_ref().clone(),
specialization_var,
expected,
Category::Storage(file!(), line!()),
region,
file!(),
line!(),
);
let lookup_constr = constraints.lookup(
symbol,
@ -435,7 +436,7 @@ pub fn constrain_expr(
region,
);
// Make sure we attempt to resolve the specialization, if we need to.
// Make sure we attempt to resolve the specialization, if we can.
if let Some(specialization_id) = specialization_id {
env.resolutions_to_make.push(OpportunisticResolve {
specialization_variable: specialization_var,