Support Self in mir lowering

This commit is contained in:
hkalbasi 2023-07-30 23:05:10 +03:30
parent cecbed98d8
commit a9d81ae89c
2 changed files with 45 additions and 4 deletions

View File

@ -613,6 +613,50 @@ fn main() {
); );
} }
#[test]
fn self_with_capital_s() {
check_pass(
r#"
//- minicore: fn, add, copy
struct S1;
impl S1 {
fn f() {
Self;
}
}
struct S2 {
f1: i32,
}
impl S2 {
fn f() {
Self { f1: 5 };
}
}
struct S3(i32);
impl S3 {
fn f() {
Self(2);
Self;
let this = Self;
this(2);
}
}
fn main() {
S1::f();
S2::f();
S3::f();
}
"#,
);
}
#[test] #[test]
fn syscalls() { fn syscalls() {
check_pass( check_pass(

View File

@ -486,13 +486,10 @@ fn lower_expr_to_place_without_adjust(
); );
Ok(Some(current)) Ok(Some(current))
} }
ValueNs::FunctionId(_) | ValueNs::StructId(_) => { ValueNs::FunctionId(_) | ValueNs::StructId(_) | ValueNs::ImplSelf(_) => {
// It's probably a unit struct or a zero sized function, so no action is needed. // It's probably a unit struct or a zero sized function, so no action is needed.
Ok(Some(current)) Ok(Some(current))
} }
it => {
not_supported!("unknown name {it:?} in value name space");
}
} }
} }
Expr::If { condition, then_branch, else_branch } => { Expr::If { condition, then_branch, else_branch } => {