mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
fix: #415
This commit is contained in:
parent
62b06022cb
commit
5eb680cb21
5 changed files with 25 additions and 3 deletions
|
@ -1377,6 +1377,9 @@ impl HasType for Call {
|
||||||
if let Some(attr) = self.attr_name.as_mut() {
|
if let Some(attr) = self.attr_name.as_mut() {
|
||||||
Some(attr.ref_mut_t())
|
Some(attr.ref_mut_t())
|
||||||
} else {
|
} else {
|
||||||
|
if let Expr::Call(call) = self.obj.as_ref() {
|
||||||
|
call.return_t()?;
|
||||||
|
}
|
||||||
Some(self.obj.ref_mut_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)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -1024,13 +1024,21 @@ impl ASTLowerer {
|
||||||
.module
|
.module
|
||||||
.context
|
.context
|
||||||
.subtype_of(vi.t.return_t().unwrap(), &Type::Bool));
|
.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 {
|
let attr_name = if let Some(attr_name) = call.attr_name {
|
||||||
self.inc_ref(&vi, &attr_name.name);
|
self.inc_ref(&vi, &attr_name.name);
|
||||||
Some(hir::Identifier::new(attr_name, None, vi))
|
Some(hir::Identifier::new(attr_name, None, vi))
|
||||||
} else {
|
} else {
|
||||||
|
if let hir::Expr::Call(call) = &obj {
|
||||||
|
if call.return_t().is_some() {
|
||||||
*obj.ref_mut_t() = vi.t;
|
*obj.ref_mut_t() = vi.t;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*obj.ref_mut_t() = vi.t;
|
||||||
|
}
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let mut call = hir::Call::new(obj, attr_name, hir_args);
|
let mut call = hir::Call::new(obj, attr_name, hir_args);
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub trait HasType {
|
||||||
// 関数呼び出しの場合、.ref_t()は戻り値を返し、signature_t()は関数全体の型を返す
|
// 関数呼び出しの場合、.ref_t()は戻り値を返し、signature_t()は関数全体の型を返す
|
||||||
fn signature_t(&self) -> Option<&Type>;
|
fn signature_t(&self) -> Option<&Type>;
|
||||||
// 最後にHIR全体の型変数を消すために使う
|
// 最後に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 ref_mut_t(&mut self) -> &mut Type;
|
||||||
fn signature_mut_t(&mut self) -> Option<&mut Type>;
|
fn signature_mut_t(&mut self) -> Option<&mut Type>;
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -11,3 +11,5 @@ print! f3(1) 2 # ERR
|
||||||
|
|
||||||
f4 x = (y) => x
|
f4 x = (y) => x
|
||||||
print! f4(1) 2 # OK
|
print! f4(1) 2 # OK
|
||||||
|
|
||||||
|
_ = Array() [1, 2] # ERR
|
||||||
|
|
|
@ -309,7 +309,7 @@ fn exec_subtyping_err() -> Result<(), ()> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exec_callable() -> Result<(), ()> {
|
fn exec_callable() -> Result<(), ()> {
|
||||||
expect_failure("tests/should_err/callable.er", 0, 4)
|
expect_failure("tests/should_err/callable.er", 0, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue