From a9f845bd005cf9e728736d49b59d86e733743d1d Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Tue, 22 Nov 2022 11:46:20 +0000 Subject: [PATCH] Adds more insert_unified_type to unify and unify_right. 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. --- .../semantic_analysis/namespace/trait_map.rs | 1 + sway-core/src/type_system/unify.rs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index a359c404725..220d2d4b5dd 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -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) } diff --git a/sway-core/src/type_system/unify.rs b/sway-core/src/type_system/unify.rs index 433eef78cee..4e72e453a86 100644 --- a/sway-core/src/type_system/unify.rs +++ b/sway-core/src/type_system/unify.rs @@ -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) { @@ -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