Skip to content

Commit

Permalink
fix abi with super traits for encoding v1
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Apr 24, 2024
1 parent ecfe500 commit a476069
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 21 additions & 15 deletions sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,12 @@ impl TyDecl {
Err(err) => return Ok(ty::TyDecl::ErrorRecovery(span, err)),
};

// if this ImplTrait implements a trait and not an ABI,
// we insert its methods into the context
// otherwise, if it implements an ABI,
// we insert its methods with a prefix
let emp_vec = vec![];
let impl_trait_items = if let Ok(ty::TyDecl::TraitDecl { .. }) =
ctx.namespace().resolve_call_path_typed(
&Handler::default(),
engines,
&impl_trait.trait_name,
ctx.self_type(),
) {
&impl_trait.items
} else {
// Insert prefixed symbols when implementing_for is Contract
let is_contract = engines
.te()
.get(impl_trait.implementing_for.type_id)
.is_contract();
if is_contract {
for i in &impl_trait.items {
if let ty::TyTraitItem::Fn(f) = i {
let decl = engines.de().get(f.id());
Expand All @@ -314,8 +306,22 @@ impl TyDecl {
});
}
}
}

&emp_vec
// Choose which items are going to be visible depending if this is an abi impl
// or trait impl
let t = ctx.namespace().resolve_call_path_typed(
&Handler::default(),
engines,
&impl_trait.trait_name,
ctx.self_type(),
);

let empty_vec = vec![];
let impl_trait_items = if let Ok(ty::TyDecl::TraitDecl { .. }) = t {
&impl_trait.items
} else {
&empty_vec
};

ctx.insert_trait_implementation(
Expand Down
4 changes: 4 additions & 0 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,10 @@ impl TypeInfo {
matches!(self, TypeInfo::Array(_, _))
}

pub fn is_contract(&self) -> bool {
matches!(self, TypeInfo::Contract)
}

pub fn is_struct(&self) -> bool {
matches!(self, TypeInfo::Struct(_))
}
Expand Down

0 comments on commit a476069

Please sign in to comment.