Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Self not found in match statement. #4459

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ty::TyDecl> = 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![];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}