mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
chore(els): display hover etc. even when check fails
This commit is contained in:
parent
a4ace1caae
commit
4a46e8f5a8
2 changed files with 44 additions and 33 deletions
|
@ -25,7 +25,7 @@ use crate::ty::constructors::{
|
|||
use crate::ty::free::{Constraint, FreeKind, HasLevel};
|
||||
use crate::ty::typaram::TyParam;
|
||||
use crate::ty::value::{GenTypeObj, TypeObj, ValueObj};
|
||||
use crate::ty::{HasType, ParamTy, SubrType, Type, Visibility};
|
||||
use crate::ty::{HasType, ParamTy, SubrType, Type, Visibility, VisibilityModifier};
|
||||
|
||||
use crate::build_hir::HIRBuilder;
|
||||
use crate::context::{
|
||||
|
@ -627,14 +627,21 @@ impl Context {
|
|||
id: DefId,
|
||||
body_t: &Type,
|
||||
body_loc: &impl Locational,
|
||||
) -> TyCheckResult<VarInfo> {
|
||||
) -> Result<VarInfo, (TyCheckErrors, VarInfo)> {
|
||||
let mut errs = TyCheckErrors::empty();
|
||||
// already defined as const
|
||||
if sig.ident.is_const() {
|
||||
let vi = self.decls.remove(sig.ident.inspect()).unwrap();
|
||||
self.locals.insert(sig.ident.name.clone(), vi.clone());
|
||||
return Ok(vi);
|
||||
}
|
||||
let vis = self.instantiate_vis_modifier(&sig.ident.vis)?;
|
||||
let vis = match self.instantiate_vis_modifier(&sig.ident.vis) {
|
||||
Ok(vis) => vis,
|
||||
Err(es) => {
|
||||
errs.extend(es);
|
||||
VisibilityModifier::Private
|
||||
}
|
||||
};
|
||||
let muty = if sig.ident.is_const() {
|
||||
Mutability::Const
|
||||
} else {
|
||||
|
@ -646,15 +653,16 @@ impl Context {
|
|||
let non_default_params = t.non_default_params().unwrap();
|
||||
let var_args = t.var_params();
|
||||
let default_params = t.default_params().unwrap();
|
||||
let mut errs = if let Some(spec_ret_t) = t.return_t() {
|
||||
if let Some(spec_ret_t) = t.return_t() {
|
||||
let unify_result = if let Some(t_spec) = sig.return_t_spec.as_ref() {
|
||||
self.sub_unify(body_t, spec_ret_t, t_spec, None)
|
||||
} else {
|
||||
self.sub_unify(body_t, spec_ret_t, body_loc, None)
|
||||
};
|
||||
unify_result.map_err(|errs| {
|
||||
TyCheckErrors::new(
|
||||
errs.into_iter()
|
||||
if let Err(unify_errs) = unify_result {
|
||||
let es = TyCheckErrors::new(
|
||||
unify_errs
|
||||
.into_iter()
|
||||
.map(|e| {
|
||||
let expect = if cfg!(feature = "debug") {
|
||||
spec_ret_t.clone()
|
||||
|
@ -678,17 +686,12 @@ impl Context {
|
|||
)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
let return_t = if errs.is_err() {
|
||||
Type::Failure
|
||||
} else {
|
||||
// NOTE: not `body_t.clone()` because the body may contain `return`
|
||||
t.return_t().unwrap().clone()
|
||||
};
|
||||
);
|
||||
errs.extend(es);
|
||||
}
|
||||
}
|
||||
// NOTE: not `body_t.clone()` because the body may contain `return`
|
||||
let return_t = t.return_t().unwrap().clone();
|
||||
let sub_t = if sig.ident.is_procedural() {
|
||||
proc(
|
||||
non_default_params.clone(),
|
||||
|
@ -718,14 +721,7 @@ impl Context {
|
|||
&vi.t,
|
||||
&found_t,
|
||||
);
|
||||
match errs {
|
||||
Ok(()) => {
|
||||
errs = Err(TyCheckErrors::from(err));
|
||||
}
|
||||
Err(ref mut es) => {
|
||||
es.push(err);
|
||||
}
|
||||
}
|
||||
errs.push(err);
|
||||
}
|
||||
vi.py_name
|
||||
} else {
|
||||
|
@ -754,8 +750,11 @@ impl Context {
|
|||
let vis = if vi.vis.is_private() { "::" } else { "." };
|
||||
log!(info "Registered {}{}{name}: {}", self.name, vis, &vi.t);
|
||||
self.locals.insert(name.clone(), vi.clone());
|
||||
errs?;
|
||||
Ok(vi)
|
||||
if errs.is_empty() {
|
||||
Ok(vi)
|
||||
} else {
|
||||
Err((errs, vi))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn fake_subr_assign(
|
||||
|
|
|
@ -1583,12 +1583,18 @@ impl ASTLowerer {
|
|||
match self.lower_block(body.block) {
|
||||
Ok(block) => {
|
||||
let found_body_t = self.module.context.squash_tyvar(block.t());
|
||||
let vi = self.module.context.outer.as_mut().unwrap().assign_subr(
|
||||
let vi = match self.module.context.outer.as_mut().unwrap().assign_subr(
|
||||
&sig,
|
||||
body.id,
|
||||
&found_body_t,
|
||||
block.last().unwrap(),
|
||||
)?;
|
||||
) {
|
||||
Ok(vi) => vi,
|
||||
Err((errs, vi)) => {
|
||||
self.errs.extend(errs);
|
||||
vi
|
||||
}
|
||||
};
|
||||
let ident = hir::Identifier::new(sig.ident, None, vi);
|
||||
let sig =
|
||||
hir::SubrSignature::new(ident, sig.bounds, params, sig.return_t_spec);
|
||||
|
@ -1596,13 +1602,19 @@ impl ASTLowerer {
|
|||
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
||||
}
|
||||
Err(errs) => {
|
||||
let vi = self.module.context.outer.as_mut().unwrap().assign_subr(
|
||||
self.errs.extend(errs);
|
||||
let vi = match self.module.context.outer.as_mut().unwrap().assign_subr(
|
||||
&sig,
|
||||
ast::DefId(0),
|
||||
&Type::Failure,
|
||||
&sig,
|
||||
)?;
|
||||
self.errs.extend(errs);
|
||||
) {
|
||||
Ok(vi) => vi,
|
||||
Err((errs, vi)) => {
|
||||
self.errs.extend(errs);
|
||||
vi
|
||||
}
|
||||
};
|
||||
let ident = hir::Identifier::new(sig.ident, None, vi);
|
||||
let sig =
|
||||
hir::SubrSignature::new(ident, sig.bounds, params, sig.return_t_spec);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue