mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix: refinement type assert cast bug
This commit is contained in:
parent
121738da74
commit
13f303fbfb
4 changed files with 22 additions and 1 deletions
|
@ -141,6 +141,14 @@ impl<T> Triple<T, T> {
|
|||
Triple::Ok(a) | Triple::Err(a) => Some(a),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_or(self, default: T) -> T {
|
||||
match self {
|
||||
Triple::None => default,
|
||||
Triple::Ok(ok) => ok,
|
||||
Triple::Err(err) => err,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E: std::error::Error> Triple<T, E> {
|
||||
|
|
|
@ -3657,6 +3657,7 @@ impl Context {
|
|||
/// ```erg
|
||||
/// recover_typarams(Int, Nat) == Nat
|
||||
/// recover_typarams(Array!(Int, _), Array(Nat, 2)) == Array!(Nat, 2)
|
||||
/// recover_typarams(Str or NoneType, {"a", "b"}) == {"a", "b"}
|
||||
/// ```
|
||||
/// ```erg
|
||||
/// # REVIEW: should be?
|
||||
|
@ -3667,7 +3668,8 @@ impl Context {
|
|||
let is_never =
|
||||
self.subtype_of(&intersec, &Type::Never) && guard.to.as_ref() != &Type::Never;
|
||||
if !is_never {
|
||||
return Ok(intersec);
|
||||
let min = self.min(&intersec, &guard.to).merge_or(&intersec);
|
||||
return Ok(min.clone());
|
||||
}
|
||||
if guard.to.is_monomorphic() {
|
||||
if self.related(base, &guard.to) {
|
||||
|
|
|
@ -30,3 +30,11 @@ c_new x, y = C.new x, y
|
|||
C = Class Int
|
||||
C.
|
||||
new x, y = Self x + y
|
||||
|
||||
val!() =
|
||||
for! [{ "a": "b" }], (pkg as {Str: Str}) =>
|
||||
x = pkg.get("a", "c")
|
||||
assert x in {"b"}
|
||||
val!::return x
|
||||
"d"
|
||||
val = val!()
|
||||
|
|
|
@ -87,6 +87,9 @@ fn _test_infer_types() -> Result<(), ()> {
|
|||
let c_new_t = func2(add_r, r, c.clone()).quantify();
|
||||
module.context.assert_var_type("c_new", &c_new_t)?;
|
||||
module.context.assert_attr_type(&c, "new", &c_new_t)?;
|
||||
module
|
||||
.context
|
||||
.assert_var_type("val", &v_enum(set! { "b".into(), "d".into() }))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue