mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 05:11:09 +00:00
eliminate todo!
s
This commit is contained in:
parent
7a4b9e3652
commit
5342edcf4d
2 changed files with 60 additions and 18 deletions
|
@ -8,8 +8,8 @@ use erg_common::python_util::BUILTIN_PYTHON_MODS;
|
||||||
use erg_common::set::Set;
|
use erg_common::set::Set;
|
||||||
use erg_common::traits::{Locational, Stream};
|
use erg_common::traits::{Locational, Stream};
|
||||||
use erg_common::vis::Visibility;
|
use erg_common::vis::Visibility;
|
||||||
use erg_common::Str;
|
|
||||||
use erg_common::{enum_unwrap, get_hash, log, set};
|
use erg_common::{enum_unwrap, get_hash, log, set};
|
||||||
|
use erg_common::{fn_name, Str};
|
||||||
|
|
||||||
use ast::{Decorator, DefId, Identifier, OperationKind, VarName};
|
use ast::{Decorator, DefId, Identifier, OperationKind, VarName};
|
||||||
use erg_parser::ast;
|
use erg_parser::ast;
|
||||||
|
@ -558,10 +558,16 @@ impl Context {
|
||||||
ident: &Identifier,
|
ident: &Identifier,
|
||||||
decorators: &Set<Decorator>,
|
decorators: &Set<Decorator>,
|
||||||
failure_t: Type,
|
failure_t: Type,
|
||||||
) {
|
) -> TyCheckResult<()> {
|
||||||
// already defined as const
|
// already defined as const
|
||||||
if ident.is_const() {
|
if ident.is_const() {
|
||||||
let vi = self.decls.remove(ident.inspect()).unwrap();
|
let Some(vi) = self.decls.remove(ident.inspect()) else {
|
||||||
|
return Err(TyCheckErrors::from(TyCheckError::unreachable(
|
||||||
|
self.cfg.input.clone(),
|
||||||
|
fn_name!(),
|
||||||
|
line!(),
|
||||||
|
)));
|
||||||
|
};
|
||||||
self.locals.insert(ident.name.clone(), vi);
|
self.locals.insert(ident.name.clone(), vi);
|
||||||
}
|
}
|
||||||
let muty = if ident.is_const() {
|
let muty = if ident.is_const() {
|
||||||
|
@ -591,6 +597,7 @@ impl Context {
|
||||||
);
|
);
|
||||||
log!(info "Registered {}::{name}: {}", self.name, &vi.t);
|
log!(info "Registered {}::{name}: {}", self.name, &vi.t);
|
||||||
self.locals.insert(name.clone(), vi);
|
self.locals.insert(name.clone(), vi);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// To allow forward references and recursive definitions
|
// To allow forward references and recursive definitions
|
||||||
|
@ -1494,7 +1501,12 @@ impl Context {
|
||||||
if let Some(vi) = self.get_mut_current_scope_var(ident.inspect()) {
|
if let Some(vi) = self.get_mut_current_scope_var(ident.inspect()) {
|
||||||
vi.t = t;
|
vi.t = t;
|
||||||
} else {
|
} else {
|
||||||
todo!()
|
return Err(TyCheckErrors::from(TyCheckError::feature_error(
|
||||||
|
self.cfg.input.clone(),
|
||||||
|
acc.loc(),
|
||||||
|
&format!("casting {acc}"),
|
||||||
|
self.caused_by(),
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -42,6 +42,26 @@ use crate::varinfo::{VarInfo, VarKind};
|
||||||
use crate::AccessKind;
|
use crate::AccessKind;
|
||||||
use Visibility::*;
|
use Visibility::*;
|
||||||
|
|
||||||
|
macro_rules! unreachable_error {
|
||||||
|
($self: ident) => {
|
||||||
|
Err(LowerErrors::from(LowerError::unreachable(
|
||||||
|
$self.cfg.input.clone(),
|
||||||
|
fn_name!(),
|
||||||
|
line!(),
|
||||||
|
)))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! todo_error {
|
||||||
|
($self: ident, $loc: expr, $name: expr) => {
|
||||||
|
Err(LowerErrors::from(LowerError::feature_error(
|
||||||
|
$self.cfg.input.clone(),
|
||||||
|
$loc,
|
||||||
|
$name,
|
||||||
|
$self.ctx.caused_by(),
|
||||||
|
)))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks & infers types of an AST, and convert (lower) it into a HIR
|
/// Checks & infers types of an AST, and convert (lower) it into a HIR
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ASTLowerer {
|
pub struct ASTLowerer {
|
||||||
|
@ -317,7 +337,7 @@ impl ASTLowerer {
|
||||||
ast::Array::WithLength(arr) => {
|
ast::Array::WithLength(arr) => {
|
||||||
Ok(hir::Array::WithLength(self.lower_array_with_length(arr)?))
|
Ok(hir::Array::WithLength(self.lower_array_with_length(arr)?))
|
||||||
}
|
}
|
||||||
other => todo!("{other}"),
|
other => todo_error!(self, other.loc(), "array comprehension"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +622,7 @@ impl ASTLowerer {
|
||||||
log!(info "enter {}({dict})", fn_name!());
|
log!(info "enter {}({dict})", fn_name!());
|
||||||
match dict {
|
match dict {
|
||||||
ast::Dict::Normal(set) => Ok(hir::Dict::Normal(self.lower_normal_dict(set)?)),
|
ast::Dict::Normal(set) => Ok(hir::Dict::Normal(self.lower_normal_dict(set)?)),
|
||||||
other => todo!("{other}"),
|
other => todo_error!(self, other.loc(), "dict comprehension"),
|
||||||
// ast::Dict::WithLength(set) => Ok(hir::Dict::WithLength(self.lower_dict_with_length(set)?)),
|
// ast::Dict::WithLength(set) => Ok(hir::Dict::WithLength(self.lower_dict_with_length(set)?)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,9 +726,7 @@ impl ASTLowerer {
|
||||||
let acc = hir::Accessor::Attr(hir::Attribute::new(obj, ident));
|
let acc = hir::Accessor::Attr(hir::Attribute::new(obj, ident));
|
||||||
Ok(acc)
|
Ok(acc)
|
||||||
}
|
}
|
||||||
ast::Accessor::TypeApp(_t_app) => {
|
ast::Accessor::TypeApp(t_app) => todo_error!(self, t_app.loc(), "type application"),
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
// TupleAttr, Subscr are desugared
|
// TupleAttr, Subscr are desugared
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -1168,14 +1186,14 @@ impl ASTLowerer {
|
||||||
&sig.ident,
|
&sig.ident,
|
||||||
&sig.decorators,
|
&sig.decorators,
|
||||||
Type::Failure,
|
Type::Failure,
|
||||||
);
|
)?;
|
||||||
let block = self.lower_block(body.block)?;
|
let block = self.lower_block(body.block)?;
|
||||||
let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
||||||
let sig = hir::SubrSignature::new(ident, params);
|
let sig = hir::SubrSignature::new(ident, params);
|
||||||
let body = hir::DefBody::new(body.op, block, body.id);
|
let body = hir::DefBody::new(body.op, block, body.id);
|
||||||
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable_error!(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1199,7 +1217,7 @@ impl ASTLowerer {
|
||||||
)?,
|
)?,
|
||||||
tasc.t_spec.loc(),
|
tasc.t_spec.loc(),
|
||||||
),
|
),
|
||||||
_ => unreachable!(),
|
_ => return unreachable_error!(self),
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
self.ctx.instantiate_typespec(
|
self.ctx.instantiate_typespec(
|
||||||
|
@ -1321,7 +1339,7 @@ impl ASTLowerer {
|
||||||
) {
|
) {
|
||||||
(dunder_new_vi.t.clone(), new_vi.kind == VarKind::Auto)
|
(dunder_new_vi.t.clone(), new_vi.kind == VarKind::Auto)
|
||||||
} else {
|
} else {
|
||||||
todo!()
|
return unreachable_error!(self);
|
||||||
};
|
};
|
||||||
let require_or_sup = self.get_require_or_sup_or_base(hir_def.body.block.remove(0));
|
let require_or_sup = self.get_require_or_sup_or_base(hir_def.body.block.remove(0));
|
||||||
Ok(hir::ClassDef::new(
|
Ok(hir::ClassDef::new(
|
||||||
|
@ -1445,10 +1463,15 @@ impl ASTLowerer {
|
||||||
None,
|
None,
|
||||||
)));
|
)));
|
||||||
};
|
};
|
||||||
let (_, class_ctx) = self
|
let Some((_, class_ctx)) = self.ctx.get_mut_nominal_type_ctx(class) else {
|
||||||
.ctx
|
return Err(LowerErrors::from(LowerError::type_not_found(
|
||||||
.get_mut_nominal_type_ctx(class)
|
self.cfg.input.clone(),
|
||||||
.unwrap_or_else(|| todo!("{class} not found"));
|
line!() as usize,
|
||||||
|
trait_loc,
|
||||||
|
self.ctx.caused_by(),
|
||||||
|
class,
|
||||||
|
)));
|
||||||
|
};
|
||||||
class_ctx.register_supertrait(trait_.clone(), &trait_ctx);
|
class_ctx.register_supertrait(trait_.clone(), &trait_ctx);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1567,7 +1590,14 @@ impl ASTLowerer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
other => todo!("{other}"),
|
other => {
|
||||||
|
return todo_error!(
|
||||||
|
self,
|
||||||
|
Location::Unknown,
|
||||||
|
&format!("Impl {other}")
|
||||||
|
)
|
||||||
|
.map_err(|mut e| e.remove(0));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
TypeObj::Builtin(_typ) => {
|
TypeObj::Builtin(_typ) => {
|
||||||
let (_, ctx) = self.ctx.get_nominal_type_ctx(_typ).unwrap();
|
let (_, ctx) = self.ctx.get_nominal_type_ctx(_typ).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue