This commit is contained in:
Shunsuke Shibayama 2023-04-16 21:13:48 +09:00
parent 62b06022cb
commit 5eb680cb21
5 changed files with 25 additions and 3 deletions

View file

@ -1377,6 +1377,9 @@ impl HasType for Call {
if let Some(attr) = self.attr_name.as_mut() {
Some(attr.ref_mut_t())
} else {
if let Expr::Call(call) = self.obj.as_ref() {
call.return_t()?;
}
Some(self.obj.ref_mut_t())
}
}
@ -1417,6 +1420,14 @@ impl Call {
}
})
}
pub fn return_t(&self) -> Option<&Type> {
if let Some(attr) = self.attr_name.as_ref() {
attr.ref_t().return_t()
} else {
self.obj.ref_t().return_t()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

View file

@ -1024,13 +1024,21 @@ impl ASTLowerer {
.module
.context
.subtype_of(vi.t.return_t().unwrap(), &Type::Bool));
*vi.t.mut_return_t().unwrap() = guard;
if let Some(ret_t) = vi.t.mut_return_t() {
*ret_t = guard;
}
}
let attr_name = if let Some(attr_name) = call.attr_name {
self.inc_ref(&vi, &attr_name.name);
Some(hir::Identifier::new(attr_name, None, vi))
} else {
*obj.ref_mut_t() = vi.t;
if let hir::Expr::Call(call) = &obj {
if call.return_t().is_some() {
*obj.ref_mut_t() = vi.t;
}
} else {
*obj.ref_mut_t() = vi.t;
}
None
};
let mut call = hir::Call::new(obj, attr_name, hir_args);

View file

@ -45,6 +45,7 @@ pub trait HasType {
// 関数呼び出しの場合、.ref_t()は戻り値を返し、signature_t()は関数全体の型を返す
fn signature_t(&self) -> Option<&Type>;
// 最後にHIR全体の型変数を消すために使う
/// `x.ref_mut_t()` may panic, in which case `x` is `Call` and `x.ref_t() == Type::Failure`.
fn ref_mut_t(&mut self) -> &mut Type;
fn signature_mut_t(&mut self) -> Option<&mut Type>;
#[inline]