diff --git a/compiler/erg_compiler/codegen.rs b/compiler/erg_compiler/codegen.rs index 952c343e..89cd62a0 100644 --- a/compiler/erg_compiler/codegen.rs +++ b/compiler/erg_compiler/codegen.rs @@ -2495,6 +2495,7 @@ impl PyCodeGenerator { self.emit_expr(*tasc.expr); } Expr::Import(acc) => self.emit_import(acc), + Expr::Dummy(_) => {} } } diff --git a/compiler/erg_compiler/context/tyvar.rs b/compiler/erg_compiler/context/tyvar.rs index 8e6a7eed..128cf06c 100644 --- a/compiler/erg_compiler/context/tyvar.rs +++ b/compiler/erg_compiler/context/tyvar.rs @@ -621,7 +621,7 @@ impl Context { fn resolve_expr_t(&self, expr: &mut hir::Expr) -> SingleTyCheckResult<()> { match expr { - hir::Expr::Lit(_) => Ok(()), + hir::Expr::Lit(_) | hir::Expr::Dummy(_) => Ok(()), hir::Expr::Accessor(acc) => { let loc = acc.loc(); let t = acc.ref_mut_t(); diff --git a/compiler/erg_compiler/effectcheck.rs b/compiler/erg_compiler/effectcheck.rs index 246e84ed..44ab931d 100644 --- a/compiler/erg_compiler/effectcheck.rs +++ b/compiler/erg_compiler/effectcheck.rs @@ -191,7 +191,11 @@ impl SideEffectChecker { self.path_stack.pop(); self.block_stack.pop(); } - other => todo!("{other}"), + Expr::AttrDef(_) + | Expr::Code(_) + | Expr::Compound(_) + | Expr::Import(_) + | Expr::Dummy(_) => {} } } log!(info "the side-effects checking process has completed, found errors: {}{RESET}", self.errs.len()); @@ -275,6 +279,7 @@ impl SideEffectChecker { /// ``` fn check_expr(&mut self, expr: &Expr) { match expr { + Expr::Lit(_) => {} Expr::Def(def) => { self.check_def(def); } @@ -399,7 +404,11 @@ impl SideEffectChecker { )); } } - _ => {} + Expr::AttrDef(_) + | Expr::Code(_) + | Expr::Compound(_) + | Expr::Import(_) + | Expr::Dummy(_) => {} } } } diff --git a/compiler/erg_compiler/hir.rs b/compiler/erg_compiler/hir.rs index 67e5293a..aa6be0e7 100644 --- a/compiler/erg_compiler/hir.rs +++ b/compiler/erg_compiler/hir.rs @@ -2225,13 +2225,14 @@ pub enum Expr { Code(Block), // code object Compound(Block), // compound statement Import(Accessor), + Dummy(Block), // for mapping to Python AST } -impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import); -impl_no_type_display_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import); +impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_no_type_display_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy); impl_display_from_nested!(Expr); -impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import); -impl_t_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import); +impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy); +impl_t_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy); impl Default for Expr { fn default() -> Self { diff --git a/compiler/erg_compiler/link.rs b/compiler/erg_compiler/link.rs index fae37ead..f9455e30 100644 --- a/compiler/erg_compiler/link.rs +++ b/compiler/erg_compiler/link.rs @@ -158,6 +158,7 @@ impl<'a> Linker<'a> { } } Expr::Import(_) => unreachable!(), + Expr::Dummy(_) => {} } } @@ -279,6 +280,7 @@ impl<'a> Linker<'a> { } } Expr::Import(_) => unreachable!(), + Expr::Dummy(_) => {} } } diff --git a/compiler/erg_compiler/lower.rs b/compiler/erg_compiler/lower.rs index 498e1421..34b5785f 100644 --- a/compiler/erg_compiler/lower.rs +++ b/compiler/erg_compiler/lower.rs @@ -1765,6 +1765,8 @@ impl ASTLowerer { ast::Expr::PatchDef(defs) => Ok(hir::Expr::PatchDef(self.lower_patch_def(defs)?)), ast::Expr::AttrDef(adef) => Ok(hir::Expr::AttrDef(self.lower_attr_def(adef)?)), ast::Expr::TypeAsc(tasc) => Ok(hir::Expr::TypeAsc(self.lower_type_asc(tasc)?)), + // Checking is also performed for expressions in Dummy. However, it has no meaning in code generation + ast::Expr::Dummy(dummy) => Ok(hir::Expr::Dummy(self.lower_block(dummy)?)), other => todo!("{other}"), } } diff --git a/compiler/erg_compiler/transpile.rs b/compiler/erg_compiler/transpile.rs index af1edeb1..62692769 100644 --- a/compiler/erg_compiler/transpile.rs +++ b/compiler/erg_compiler/transpile.rs @@ -411,6 +411,7 @@ impl ScriptGenerator { } Expr::TypeAsc(tasc) => self.transpile_expr(*tasc.expr), Expr::Code(_) => todo!("transpiling importing user-defined code"), + Expr::Dummy(_) => "".to_string(), } } diff --git a/compiler/erg_parser/ast.rs b/compiler/erg_parser/ast.rs index 5b4ab6bc..6b7fb9f7 100644 --- a/compiler/erg_parser/ast.rs +++ b/compiler/erg_parser/ast.rs @@ -3527,11 +3527,13 @@ pub enum Expr { ClassDef(ClassDef), PatchDef(PatchDef), AttrDef(AttrDef), + /// for mapping to Python AST + Dummy(Block), } -impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef); +impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef, Dummy); impl_display_from_nested!(Expr); -impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef); +impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef, Dummy); impl Expr { pub fn is_match_call(&self) -> bool { diff --git a/compiler/erg_parser/desugar.rs b/compiler/erg_parser/desugar.rs index 9621f18b..fcf21a71 100644 --- a/compiler/erg_parser/desugar.rs +++ b/compiler/erg_parser/desugar.rs @@ -296,6 +296,13 @@ impl Desugarer { Expr::Methods(Methods::new(method_defs.class, method_defs.vis, new_attrs)) } Expr::Accessor(acc) => Expr::Accessor(Self::perform_desugar_acc(desugar, acc)), + Expr::Dummy(exprs) => { + let mut chunks = vec![]; + for chunk in exprs.into_iter() { + chunks.push(desugar(chunk)); + } + Expr::Dummy(Block::new(chunks)) + } } }