mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 13:11:11 +00:00
Add python shadowing mode
This commit is contained in:
parent
a6da05147c
commit
351ac57188
2 changed files with 11 additions and 5 deletions
|
@ -1093,22 +1093,24 @@ impl ASTLowerer {
|
|||
Ok(block) => {
|
||||
let found_body_t = block.ref_t();
|
||||
let outer = self.ctx.outer.as_ref().unwrap();
|
||||
let opt_expect_body_t = sig
|
||||
let opt_expect_body_vi = sig
|
||||
.inspect()
|
||||
.and_then(|name| outer.get_current_scope_var(name).map(|vi| vi.t.clone()));
|
||||
.and_then(|name| outer.get_current_scope_var(name));
|
||||
let ident = match &sig.pat {
|
||||
ast::VarPattern::Ident(ident) => ident,
|
||||
ast::VarPattern::Discard(_) => ast::Identifier::UBAR,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if let Some(expect_body_t) = opt_expect_body_t {
|
||||
if let Some(expect_body_vi) = opt_expect_body_vi {
|
||||
let python_shadowing =
|
||||
self.cfg.python_compatible_mode && expect_body_vi.kind.is_defined();
|
||||
// TODO: expect_body_t is smaller for constants
|
||||
// TODO: 定数の場合、expect_body_tのほうが小さくなってしまう
|
||||
if !sig.is_const() {
|
||||
if !sig.is_const() && !python_shadowing {
|
||||
if let Err(e) = self.var_result_t_check(
|
||||
sig.loc(),
|
||||
ident.inspect(),
|
||||
&expect_body_t,
|
||||
&expect_body_vi.t,
|
||||
found_body_t,
|
||||
) {
|
||||
self.errs.push(e);
|
||||
|
|
|
@ -63,6 +63,10 @@ impl VarKind {
|
|||
pub const fn is_parameter(&self) -> bool {
|
||||
matches!(self, Self::Parameter { .. })
|
||||
}
|
||||
|
||||
pub const fn is_defined(&self) -> bool {
|
||||
matches!(self, Self::Defined(_))
|
||||
}
|
||||
}
|
||||
|
||||
/// Has information about the type, variability, visibility, and where the variable was defined (or declared, generated)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue