fix: array type bug

This commit is contained in:
Shunsuke Shibayama 2023-12-29 12:09:59 +09:00
parent b5f5876631
commit cf726fe4a8
4 changed files with 19 additions and 2 deletions

View file

@ -413,7 +413,14 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
{ {
return Err(self.elem_err(&l, &r, elem)); return Err(self.elem_err(&l, &r, elem));
} // else(OK): e.g. [1, "a": Str or Int] } // else(OK): e.g. [1, "a": Str or Int]
} else { }
// OK: ?T(:> {"a"}) or ?U(:> {"b"}) or {"c", "d"} => {"a", "b", "c", "d"} <: Str
else if self
.module
.context
.coerce(union_.clone(), &())
.map_or(true, |coerced| coerced.union_pair().is_some())
{
return Err(self.elem_err(&l, &r, elem)); return Err(self.elem_err(&l, &r, elem));
} }
} }

View file

@ -5,3 +5,8 @@ print! arr[2][0] # ERR
dict = {"a": {"a": 1}, "b": {"b": 2}} dict = {"a": {"a": 1}, "b": {"b": 2}}
print! dict["c"]["a"] # ERR print! dict["c"]["a"] # ERR
print! dict["a"]["c"] # ERR print! dict["a"]["c"] # ERR
ab = if True:
do "a"
do "b"
_ = [1, 2, ab] # NG

View file

@ -5,3 +5,8 @@ print! x
dic = {"a": {"a": 1}, "b": {"b": 2}} dic = {"a": {"a": 1}, "b": {"b": 2}}
y = dic["a"]["a"] y = dic["a"]["a"]
print! y print! y
ab = if True: # x: {"a"} or {"b"}
do "a"
do "b"
_ = ["c", "d", ab] # OK

View file

@ -482,7 +482,7 @@ fn exec_class_attr_err() -> Result<(), ()> {
#[test] #[test]
fn exec_collection_err() -> Result<(), ()> { fn exec_collection_err() -> Result<(), ()> {
expect_failure("tests/should_err/collection.er", 0, 4) expect_failure("tests/should_err/collection.er", 0, 5)
} }
#[test] #[test]