feat: add ReDef.t_spec

This commit is contained in:
Shunsuke Shibayama 2024-08-11 14:18:15 +09:00
parent cd9973e800
commit 79b1c1394d
4 changed files with 10 additions and 4 deletions

View file

@ -897,7 +897,7 @@ impl Context {
Str,
vec![kw(KW_PAT, Str), kw(KW_INTO, Str)],
None,
vec![],
vec![kw(KW_COUNT, Int)],
None,
Str,
);

View file

@ -744,6 +744,7 @@ const KW_EPSILON: &str = "epsilon";
const KW_PATH: &str = "Path";
const KW_NDIGITS: &str = "ndigits";
const KW_BYTES_OR_BUFFER: &str = "bytes_or_buffer";
const KW_COUNT: &str = "count";
pub fn builtins_path() -> PathBuf {
erg_pystd_path().join("builtins.d.er")

View file

@ -5725,6 +5725,7 @@ impl Def {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ReDef {
pub attr: Accessor,
pub t_spec: Option<TypeSpecWithOp>,
pub expr: Box<Expr>,
}
@ -5742,9 +5743,10 @@ impl_locational!(ReDef, attr, expr);
#[pymethods]
impl ReDef {
#[staticmethod]
pub fn new(attr: Accessor, expr: Expr) -> Self {
pub fn new(attr: Accessor, t_spec: Option<TypeSpecWithOp>, expr: Expr) -> Self {
Self {
attr,
t_spec,
expr: Box::new(expr),
}
}

View file

@ -332,10 +332,13 @@ impl Desugarer {
.collect();
Expr::PatchDef(PatchDef::new(def, methods))
}
Expr::ReDef(redef) => {
Expr::ReDef(mut redef) => {
let expr = desugar(*redef.expr);
if let Some(t_op) = &mut redef.t_spec {
*t_op.t_spec_as_expr = desugar(*t_op.t_spec_as_expr.clone());
}
let attr = Self::perform_desugar_acc(desugar, redef.attr);
Expr::ReDef(ReDef::new(attr, expr))
Expr::ReDef(ReDef::new(attr, redef.t_spec, expr))
}
Expr::Lambda(mut lambda) => {
let mut chunks = vec![];