Skip to content

Commit

Permalink
Adds more insert_unified_type to unify and unify_right.
Browse files Browse the repository at this point in the history
Adds a comment as requested in review.

Adds more insert_unified_type to unify and unify_right which
covers one case that does not currently pass in CI until #3391 is merged.
  • Loading branch information
esdrubal committed Nov 22, 2022
1 parent 839e4cf commit a9f845b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ fn are_equal_minus_dynamic_types(left: TypeId, right: TypeId) -> bool {
(TypeInfo::RawUntypedPtr, TypeInfo::RawUntypedPtr) => true,
(TypeInfo::RawUntypedSlice, TypeInfo::RawUntypedSlice) => true,
(TypeInfo::UnknownGeneric { .. }, TypeInfo::UnknownGeneric { .. }) => {
// return true if left and right were unified previously
get_unified_types(left).contains(&right) || get_unified_types(right).contains(&left)
}

Expand Down
17 changes: 12 additions & 5 deletions sway-core/src/type_system/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub(super) fn unify(
},
) if rn.as_str() == en.as_str() && rtc == etc => {
type_engine.insert_unified_type(received, expected);
type_engine.insert_unified_type(expected, received);
(vec![], vec![])
}
(ref r @ UnknownGeneric { .. }, e) => match type_engine.slab.replace(received, r, e) {
Expand Down Expand Up @@ -412,11 +413,17 @@ pub(super) fn unify_right(
name: en,
trait_constraints: etc,
},
) if rn.as_str() == en.as_str() && rtc == etc => (vec![], vec![]),
(r, ref e @ UnknownGeneric { .. }) => match type_engine.slab.replace(expected, e, r) {
None => (vec![], vec![]),
Some(_) => unify_right(type_engine, received, expected, span, help_text),
},
) if rn.as_str() == en.as_str() && rtc == etc => {
type_engine.insert_unified_type(received, expected);
(vec![], vec![])
}
(r, ref e @ UnknownGeneric { .. }) => {
type_engine.insert_unified_type(received, expected);
match type_engine.slab.replace(expected, e, r) {
None => (vec![], vec![]),
Some(_) => unify_right(type_engine, received, expected, span, help_text),
}
}
// this case is purposefully removed because it should cause an
// error. trying to unify_right a generic with anything other an an
// unknown or another generic is a type error
Expand Down

0 comments on commit a9f845b

Please sign in to comment.