mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
Fix an unintended behavior with const-fn
This commit is contained in:
parent
47ea02c832
commit
73dd785eeb
4 changed files with 17 additions and 14 deletions
|
@ -133,6 +133,8 @@ impl Context {
|
|||
Accessor::Ident(ident) => {
|
||||
if let Some(val) = self.rec_get_const_obj(ident.inspect()) {
|
||||
Ok(val.clone())
|
||||
} else if self.kind.is_subr() {
|
||||
feature_error!(self, ident.loc(), "const parameters")
|
||||
} else if ident.is_const() {
|
||||
Err(EvalErrors::from(EvalError::no_var_error(
|
||||
self.cfg.input.clone(),
|
||||
|
|
|
@ -14,7 +14,6 @@ use std::path::PathBuf;
|
|||
|
||||
use erg_common::config::ErgConfig;
|
||||
use erg_common::dict;
|
||||
use erg_common::env::erg_pystd_path;
|
||||
use erg_common::error::Location;
|
||||
use erg_common::fresh::fresh_varname;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -414,7 +413,7 @@ const KW_SUPER: &str = "Super";
|
|||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
pub fn builtins_path() -> PathBuf {
|
||||
erg_pystd_path().join("builtins.d.er")
|
||||
erg_common::env::erg_pystd_path().join("builtins.d.er")
|
||||
}
|
||||
#[cfg(feature = "no_std")]
|
||||
pub fn builtins_path() -> PathBuf {
|
||||
|
|
|
@ -211,15 +211,19 @@ impl ContextKind {
|
|||
matches!(self, Self::Class | Self::Trait | Self::StructuralTrait)
|
||||
}
|
||||
|
||||
pub fn is_class(&self) -> bool {
|
||||
pub const fn is_subr(&self) -> bool {
|
||||
matches!(self, Self::Func | Self::Proc)
|
||||
}
|
||||
|
||||
pub const fn is_class(&self) -> bool {
|
||||
matches!(self, Self::Class)
|
||||
}
|
||||
|
||||
pub fn is_trait(&self) -> bool {
|
||||
pub const fn is_trait(&self) -> bool {
|
||||
matches!(self, Self::Trait | Self::StructuralTrait)
|
||||
}
|
||||
|
||||
pub fn is_patch(&self) -> bool {
|
||||
pub const fn is_patch(&self) -> bool {
|
||||
matches!(self, Self::Patch(_) | Self::GluePatch(_))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use erg_common::set::Set;
|
|||
use erg_common::traits::{Locational, Stream};
|
||||
use erg_common::vis::Visibility;
|
||||
use erg_common::{enum_unwrap, get_hash, log, set};
|
||||
use erg_common::{fn_name, Str};
|
||||
use erg_common::Str;
|
||||
|
||||
use ast::{Decorator, DefId, Identifier, OperationKind, SimpleTypeSpec, VarName};
|
||||
use erg_parser::ast::{self, ConstIdentifier};
|
||||
|
@ -599,14 +599,12 @@ impl Context {
|
|||
) -> TyCheckResult<()> {
|
||||
// already defined as const
|
||||
if ident.is_const() {
|
||||
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);
|
||||
if let Some(vi) = self.decls.remove(ident.inspect()) {
|
||||
self.locals.insert(ident.name.clone(), vi);
|
||||
} else {
|
||||
log!(err "not found: {}", ident.name);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let muty = if ident.is_const() {
|
||||
Mutability::Const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue