diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index 928d5d0dd3e..69177116434 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -305,6 +305,17 @@ impl ty::TyImplTrait { .with_help_text("") .with_type_annotation(type_engine.insert(decl_engine, TypeInfo::Unknown)); + // Insert implementing type decl as `Self` symbol. + let self_decl: Option = match type_engine.get(implementing_for.type_id) { + TypeInfo::Enum(r) => Some(r.into()), + TypeInfo::Struct(r) => Some(r.into()), + _ => None, + }; + if let Some(self_decl) = self_decl { + ctx.namespace + .insert_symbol(Ident::new_no_span("Self".to_string()), self_decl); + } + // type check the items inside of the impl block let mut new_items = vec![]; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_with_self/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_with_self/src/main.sw index 0f6d57753cd..240a54ba15c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_with_self/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_with_self/src/main.sw @@ -18,11 +18,22 @@ impl Eq for Initialized { } } +impl Initialized { + fn foo(self) -> bool { + match self { + Self::True(_) => true, + Self::False(_) => false, + } + } +} + fn main() -> u64 { let a = Initialized::True; let b = Initialized::False; let c = a == b; assert(c == false); + assert(a.foo()); + 1 }