Skip to content

Commit

Permalink
Merge branch 'master' into vaivaswatha/metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
IGI-111 authored Oct 29, 2024
2 parents e0ad271 + 5ff7c39 commit 4ec5f46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sway-core/src/type_system/ast_elements/type_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl TypeParameter {
// Type check trait constraints only after type checking all type parameters.
// This is required because a trait constraint may use other type parameters.
// Ex: `struct Struct2<A, B> where A : MyAdd<B>`
for type_param in &new_type_params {
for type_param in new_type_params.iter_mut() {
TypeParameter::type_check_trait_constraints(handler, ctx.by_ref(), type_param)?;
}

Expand Down Expand Up @@ -327,7 +327,7 @@ impl TypeParameter {
fn type_check_trait_constraints(
handler: &Handler,
mut ctx: TypeCheckContext,
type_parameter: &TypeParameter,
type_parameter: &mut TypeParameter,
) -> Result<(), ErrorEmitted> {
let type_engine = ctx.engines.te();

Expand Down Expand Up @@ -372,6 +372,8 @@ impl TypeParameter {
},
);

type_parameter.trait_constraints = trait_constraints_with_supertraits;

// Insert the trait constraints into the namespace.
type_parameter.insert_into_namespace_constraints(handler, ctx.by_ref())?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ impl<K> CallTrait<K> where K: Trait {
}
}

// https://github.com/FuelLabs/sway/issues/6382
trait Devour<T> { fn eat(t: T); }
struct Brain { }
struct Zombie { }

impl Devour<Brain> for Zombie {
fn eat(_b: Brain) { }
}

fn feed<T, U>(t: T) where U: Devour<T> {
U::eat(t);
}

fn main() -> bool {
let _ = call_trait(1);
let ct = CallTrait::<u64> {};
assert(ct.call_trait(1) == 42);

// https://github.com/FuelLabs/sway/issues/6382
let b = Brain{};
feed::<Brain, Zombie>(b);

true
}

0 comments on commit 4ec5f46

Please sign in to comment.