fix: [x; _] bug

This commit is contained in:
Shunsuke Shibayama 2023-10-02 22:50:17 +09:00
parent cce95e7210
commit 24da5cdfbd
4 changed files with 30 additions and 0 deletions

View file

@ -1809,6 +1809,10 @@ impl Context {
}
Ok(array_t(union, TyParam::value(len)))
}
TyParam::UnsizedArray(elem) => {
let elem = self.convert_tp_into_type(*elem)?;
Ok(unknown_len_array_t(elem))
}
TyParam::Set(tps) => {
let mut union = Type::Never;
for tp in tps.iter() {
@ -1874,6 +1878,10 @@ impl Context {
}
Ok(ValueObj::Array(new.into()))
}
TyParam::UnsizedArray(elem) => {
let elem = self.convert_tp_into_value(*elem)?;
Ok(ValueObj::UnsizedArray(Box::new(elem)))
}
TyParam::Tuple(tys) => {
let mut new = vec![];
for elem in tys {
@ -1978,6 +1986,13 @@ impl Context {
}
Ok(TyParam::Array(new_arr))
}
ValueObj::UnsizedArray(elem) => {
let tp = match Self::convert_value_into_tp(*elem) {
Ok(tp) => tp,
Err(tp) => tp,
};
Ok(TyParam::UnsizedArray(Box::new(tp)))
}
ValueObj::Tuple(vs) => {
let mut new_ts = vec![];
for v in vs.iter().cloned() {

View file

@ -237,6 +237,7 @@ pub enum TyParam {
Value(ValueObj),
Type(Box<Type>),
Array(Vec<TyParam>),
UnsizedArray(Box<TyParam>),
Tuple(Vec<TyParam>),
Set(Set<TyParam>),
Dict(Dict<TyParam, TyParam>),
@ -280,6 +281,7 @@ impl PartialEq for TyParam {
(Self::Value(l), Self::Value(r)) => l == r,
(Self::Type(l), Self::Type(r)) => l == r,
(Self::Array(l), Self::Array(r)) => l == r,
(Self::UnsizedArray(l), Self::UnsizedArray(r)) => l == r,
(Self::Tuple(l), Self::Tuple(r)) => l == r,
(Self::Dict(l), Self::Dict(r)) => l == r,
(Self::Record(l), Self::Record(r)) => l == r,
@ -423,6 +425,11 @@ impl LimitedDisplay for TyParam {
}
write!(f, "]")
}
Self::UnsizedArray(elem) => {
write!(f, "[")?;
elem.limited_fmt(f, limit - 1)?;
write!(f, "; _]")
}
Self::Set(st) => {
write!(f, "{{")?;
for (i, t) in st.iter().enumerate() {

View file

@ -0,0 +1,3 @@
D = Class { Int: [Str; _] }
_ = D.new {:}
_ = D.new {1: ["a"]}

View file

@ -65,6 +65,11 @@ fn exec_comprehension() -> Result<(), ()> {
expect_success("tests/should_ok/comprehension.er", 0)
}
#[test]
fn exec_container_class() -> Result<(), ()> {
expect_success("tests/should_ok/container_class.er", 0)
}
#[test]
fn exec_control() -> Result<(), ()> {
expect_success("examples/control.er", 2)