mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
feat: add ReDef.t_spec
This commit is contained in:
parent
cd9973e800
commit
79b1c1394d
4 changed files with 10 additions and 4 deletions
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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![];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue