Skip to content

Commit

Permalink
Avoids numeric decay while collecting unifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Aug 26, 2024
1 parent 9bb8102 commit fdaefda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
3 changes: 1 addition & 2 deletions sway-core/src/semantic_analysis/ast_node/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl ty::TyCodeBlock {
// The first pass does all the unifications to the variables types.
// In the second pass we use the previous_namespace on variable declaration to unify directly with the result of the first pass.
// This is required to fix the test case numeric_type_propagation and issue #6371
let _ = ctx
.by_ref()
ctx.by_ref()
.with_collecting_unifications()
.scoped(|mut ctx| {
code_block.contents.iter().for_each(|node| {
Expand Down
34 changes: 18 additions & 16 deletions sway-core/src/type_system/ast_elements/type_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,22 +501,24 @@ impl TypeParameter {
..
} = type_param;

// Check to see if the trait constraints are satisfied.
match ctx
.namespace_mut()
.module_mut(engines)
.current_items_mut()
.implemented_traits
.check_if_trait_constraints_are_satisfied_for_type(
handler,
*type_id,
trait_constraints,
access_span,
engines,
TryInsertingTraitImplOnFailure::Yes,
) {
Ok(res) => res,
Err(_) => continue,
if !ctx.collecting_unifications() {
// Check to see if the trait constraints are satisfied.
match ctx
.namespace_mut()
.module_mut(engines)
.current_items_mut()
.implemented_traits
.check_if_trait_constraints_are_satisfied_for_type(
handler,
*type_id,
trait_constraints,
access_span,
engines,
TryInsertingTraitImplOnFailure::Yes,
) {
Ok(res) => res,
Err(_) => continue,
}
}

for trait_constraint in trait_constraints {
Expand Down
4 changes: 4 additions & 0 deletions sway-core/src/type_system/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ impl TypeId {
span: &Span,
type_param: Option<TypeParameter>,
) -> Result<(), ErrorEmitted> {
if ctx.collecting_unifications() {
return Ok(());
}

let engines = ctx.engines();

let mut structure_generics = self.extract_inner_types_with_trait_constraints(engines);
Expand Down

0 comments on commit fdaefda

Please sign in to comment.