mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
Impl some effect checks
This commit is contained in:
parent
b306e05f39
commit
0262e6de69
3 changed files with 52 additions and 4 deletions
|
@ -644,7 +644,12 @@ impl Context {
|
||||||
let new_r = self.resolve_trait(*r)?;
|
let new_r = self.resolve_trait(*r)?;
|
||||||
Ok(self.intersection(&new_l, &new_r))
|
Ok(self.intersection(&new_l, &new_r))
|
||||||
}
|
}
|
||||||
Type::Or(_, _) | Type::Not(_, _) => todo!(),
|
Type::Or(l, r) => {
|
||||||
|
let new_l = self.resolve_trait(*l)?;
|
||||||
|
let new_r = self.resolve_trait(*r)?;
|
||||||
|
Ok(self.union(&new_l, &new_r))
|
||||||
|
}
|
||||||
|
Type::Not(_, _) => todo!(),
|
||||||
other => Ok(other),
|
other => Ok(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,37 @@ impl SideEffectChecker {
|
||||||
self.check_expr(&unary.expr);
|
self.check_expr(&unary.expr);
|
||||||
}
|
}
|
||||||
Expr::Accessor(_) | Expr::Lit(_) => {}
|
Expr::Accessor(_) | Expr::Lit(_) => {}
|
||||||
|
Expr::Array(array) => match array {
|
||||||
|
Array::Normal(arr) => {
|
||||||
|
for elem in arr.elems.pos_args.iter() {
|
||||||
|
self.check_expr(&elem.expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Array::WithLength(arr) => {
|
||||||
|
self.check_expr(&arr.elem);
|
||||||
|
self.check_expr(&arr.len);
|
||||||
|
}
|
||||||
|
Array::Comprehension(arr) => {
|
||||||
|
self.check_expr(&arr.elem);
|
||||||
|
self.check_expr(&arr.guard);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Expr::Tuple(tuple) => match tuple {
|
||||||
|
Tuple::Normal(tuple) => {
|
||||||
|
for elem in tuple.elems.pos_args.iter() {
|
||||||
|
self.check_expr(&elem.expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Expr::Record(rec) => {
|
||||||
|
self.path_stack.push((Str::ever("<record>"), Private));
|
||||||
|
self.block_stack.push(Instant);
|
||||||
|
for attr in rec.attrs.iter() {
|
||||||
|
self.check_def(attr);
|
||||||
|
}
|
||||||
|
self.path_stack.pop();
|
||||||
|
self.block_stack.pop();
|
||||||
|
}
|
||||||
other => todo!("{other}"),
|
other => todo!("{other}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,11 +218,18 @@ impl SideEffectChecker {
|
||||||
}
|
}
|
||||||
Expr::Array(array) => match array {
|
Expr::Array(array) => match array {
|
||||||
Array::Normal(arr) => {
|
Array::Normal(arr) => {
|
||||||
for arg in arr.elems.pos_args.iter() {
|
for elem in arr.elems.pos_args.iter() {
|
||||||
self.check_expr(&arg.expr);
|
self.check_expr(&elem.expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
other => todo!("{other}"),
|
Array::WithLength(arr) => {
|
||||||
|
self.check_expr(&arr.elem);
|
||||||
|
self.check_expr(&arr.len);
|
||||||
|
}
|
||||||
|
Array::Comprehension(arr) => {
|
||||||
|
self.check_expr(&arr.elem);
|
||||||
|
self.check_expr(&arr.guard);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Expr::Tuple(tuple) => match tuple {
|
Expr::Tuple(tuple) => match tuple {
|
||||||
Tuple::Normal(tup) => {
|
Tuple::Normal(tup) => {
|
||||||
|
@ -201,9 +239,13 @@ impl SideEffectChecker {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Expr::Record(record) => {
|
Expr::Record(record) => {
|
||||||
|
self.path_stack.push((Str::ever("<record>"), Private));
|
||||||
|
self.block_stack.push(Instant);
|
||||||
for attr in record.attrs.iter() {
|
for attr in record.attrs.iter() {
|
||||||
self.check_def(attr);
|
self.check_def(attr);
|
||||||
}
|
}
|
||||||
|
self.path_stack.pop();
|
||||||
|
self.block_stack.pop();
|
||||||
}
|
}
|
||||||
// 引数がproceduralでも関数呼び出しなら副作用なし
|
// 引数がproceduralでも関数呼び出しなら副作用なし
|
||||||
Expr::Call(call) => {
|
Expr::Call(call) => {
|
||||||
|
|
|
@ -568,6 +568,7 @@ impl ArrayWithLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: generators
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ArrayComprehension {
|
pub struct ArrayComprehension {
|
||||||
pub l_sqbr: Token,
|
pub l_sqbr: Token,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue