mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
fix: [x; _]
bug
This commit is contained in:
parent
cce95e7210
commit
24da5cdfbd
4 changed files with 30 additions and 0 deletions
|
@ -1809,6 +1809,10 @@ impl Context {
|
||||||
}
|
}
|
||||||
Ok(array_t(union, TyParam::value(len)))
|
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) => {
|
TyParam::Set(tps) => {
|
||||||
let mut union = Type::Never;
|
let mut union = Type::Never;
|
||||||
for tp in tps.iter() {
|
for tp in tps.iter() {
|
||||||
|
@ -1874,6 +1878,10 @@ impl Context {
|
||||||
}
|
}
|
||||||
Ok(ValueObj::Array(new.into()))
|
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) => {
|
TyParam::Tuple(tys) => {
|
||||||
let mut new = vec![];
|
let mut new = vec![];
|
||||||
for elem in tys {
|
for elem in tys {
|
||||||
|
@ -1978,6 +1986,13 @@ impl Context {
|
||||||
}
|
}
|
||||||
Ok(TyParam::Array(new_arr))
|
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) => {
|
ValueObj::Tuple(vs) => {
|
||||||
let mut new_ts = vec![];
|
let mut new_ts = vec![];
|
||||||
for v in vs.iter().cloned() {
|
for v in vs.iter().cloned() {
|
||||||
|
|
|
@ -237,6 +237,7 @@ pub enum TyParam {
|
||||||
Value(ValueObj),
|
Value(ValueObj),
|
||||||
Type(Box<Type>),
|
Type(Box<Type>),
|
||||||
Array(Vec<TyParam>),
|
Array(Vec<TyParam>),
|
||||||
|
UnsizedArray(Box<TyParam>),
|
||||||
Tuple(Vec<TyParam>),
|
Tuple(Vec<TyParam>),
|
||||||
Set(Set<TyParam>),
|
Set(Set<TyParam>),
|
||||||
Dict(Dict<TyParam, TyParam>),
|
Dict(Dict<TyParam, TyParam>),
|
||||||
|
@ -280,6 +281,7 @@ impl PartialEq for TyParam {
|
||||||
(Self::Value(l), Self::Value(r)) => l == r,
|
(Self::Value(l), Self::Value(r)) => l == r,
|
||||||
(Self::Type(l), Self::Type(r)) => l == r,
|
(Self::Type(l), Self::Type(r)) => l == r,
|
||||||
(Self::Array(l), Self::Array(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::Tuple(l), Self::Tuple(r)) => l == r,
|
||||||
(Self::Dict(l), Self::Dict(r)) => l == r,
|
(Self::Dict(l), Self::Dict(r)) => l == r,
|
||||||
(Self::Record(l), Self::Record(r)) => l == r,
|
(Self::Record(l), Self::Record(r)) => l == r,
|
||||||
|
@ -423,6 +425,11 @@ impl LimitedDisplay for TyParam {
|
||||||
}
|
}
|
||||||
write!(f, "]")
|
write!(f, "]")
|
||||||
}
|
}
|
||||||
|
Self::UnsizedArray(elem) => {
|
||||||
|
write!(f, "[")?;
|
||||||
|
elem.limited_fmt(f, limit - 1)?;
|
||||||
|
write!(f, "; _]")
|
||||||
|
}
|
||||||
Self::Set(st) => {
|
Self::Set(st) => {
|
||||||
write!(f, "{{")?;
|
write!(f, "{{")?;
|
||||||
for (i, t) in st.iter().enumerate() {
|
for (i, t) in st.iter().enumerate() {
|
||||||
|
|
3
tests/should_ok/container_class.er
Normal file
3
tests/should_ok/container_class.er
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
D = Class { Int: [Str; _] }
|
||||||
|
_ = D.new {:}
|
||||||
|
_ = D.new {1: ["a"]}
|
|
@ -65,6 +65,11 @@ fn exec_comprehension() -> Result<(), ()> {
|
||||||
expect_success("tests/should_ok/comprehension.er", 0)
|
expect_success("tests/should_ok/comprehension.er", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn exec_container_class() -> Result<(), ()> {
|
||||||
|
expect_success("tests/should_ok/container_class.er", 0)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exec_control() -> Result<(), ()> {
|
fn exec_control() -> Result<(), ()> {
|
||||||
expect_success("examples/control.er", 2)
|
expect_success("examples/control.er", 2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue