mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix: declared_in
is Some even if not exists
This commit is contained in:
parent
1f88084360
commit
40c8342d9e
3 changed files with 15 additions and 23 deletions
|
@ -19,6 +19,7 @@ use erg_common::env::{erg_core_decl_path, erg_pystd_path};
|
|||
use erg_common::error::Location;
|
||||
#[allow(unused_imports)]
|
||||
use erg_common::log;
|
||||
use erg_common::pathutil::NormalizedPathBuf;
|
||||
use erg_common::Str;
|
||||
use erg_common::{set, unique_in_place};
|
||||
|
||||
|
@ -1129,21 +1130,14 @@ impl Context {
|
|||
|
||||
pub(crate) fn register_methods(&mut self, t: &Type, ctx: &Self) {
|
||||
for impl_trait in ctx.super_traits.iter() {
|
||||
let declared_in = self.module_path().into();
|
||||
let declared_in = NormalizedPathBuf::from(self.module_path());
|
||||
let declared_in = declared_in.exists().then_some(declared_in);
|
||||
if let Some(mut impls) = self.trait_impls().get_mut(&impl_trait.qual_name()) {
|
||||
impls.insert(TraitImpl::new(
|
||||
t.clone(),
|
||||
impl_trait.clone(),
|
||||
Some(declared_in),
|
||||
));
|
||||
impls.insert(TraitImpl::new(t.clone(), impl_trait.clone(), declared_in));
|
||||
} else {
|
||||
self.trait_impls().register(
|
||||
impl_trait.qual_name(),
|
||||
set![TraitImpl::new(
|
||||
t.clone(),
|
||||
impl_trait.clone(),
|
||||
Some(declared_in)
|
||||
)],
|
||||
set![TraitImpl::new(t.clone(), impl_trait.clone(), declared_in)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1334,7 +1328,6 @@ impl Context {
|
|||
}
|
||||
|
||||
pub(crate) fn build_module_unsound(&self) {
|
||||
use erg_common::pathutil::NormalizedPathBuf;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::hir::{
|
||||
|
|
|
@ -6,7 +6,7 @@ use erg_common::dict::Dict;
|
|||
use erg_common::env::is_pystd_main_module;
|
||||
use erg_common::erg_util::BUILTIN_ERG_MODS;
|
||||
use erg_common::levenshtein::get_similar_name;
|
||||
use erg_common::pathutil::{DirKind, FileKind};
|
||||
use erg_common::pathutil::{DirKind, FileKind, NormalizedPathBuf};
|
||||
use erg_common::python_util::BUILTIN_PYTHON_MODS;
|
||||
use erg_common::set::Set;
|
||||
use erg_common::traits::{Locational, Stream, StructuralEq};
|
||||
|
@ -1040,17 +1040,14 @@ impl Context {
|
|||
trait_loc: &impl Locational,
|
||||
) -> TyCheckResult<()> {
|
||||
// TODO: polymorphic trait
|
||||
let declared_in = self.module_path().into();
|
||||
let declared_in = NormalizedPathBuf::from(self.module_path());
|
||||
let declared_in = declared_in.exists().then_some(declared_in);
|
||||
if let Some(mut impls) = self.trait_impls().get_mut(&trait_.qual_name()) {
|
||||
impls.insert(TraitImpl::new(
|
||||
class.clone(),
|
||||
trait_.clone(),
|
||||
Some(declared_in),
|
||||
));
|
||||
impls.insert(TraitImpl::new(class.clone(), trait_.clone(), declared_in));
|
||||
} else {
|
||||
self.trait_impls().register(
|
||||
trait_.qual_name(),
|
||||
set! {TraitImpl::new(class.clone(), trait_.clone(), Some(declared_in))},
|
||||
set! {TraitImpl::new(class.clone(), trait_.clone(), declared_in)},
|
||||
);
|
||||
}
|
||||
let trait_ctx = if let Some(trait_ctx) = self.get_nominal_type_ctx(trait_) {
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::mem;
|
|||
|
||||
use erg_common::consts::PYTHON_MODE;
|
||||
use erg_common::error::Location;
|
||||
use erg_common::pathutil::NormalizedPathBuf;
|
||||
use erg_common::traits::{Locational, Runnable, Stream};
|
||||
use erg_common::{fn_name, log, set, Str, Triple};
|
||||
|
||||
|
@ -789,19 +790,20 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
|||
ctx.level,
|
||||
);
|
||||
ctx.super_traits.push(impl_trait.clone());
|
||||
let declared_in = ctx.module_path().into();
|
||||
let declared_in = NormalizedPathBuf::from(ctx.module_path());
|
||||
let declared_in = declared_in.exists().then_some(declared_in);
|
||||
if let Some(mut impls) =
|
||||
ctx.trait_impls().get_mut(&impl_trait.qual_name())
|
||||
{
|
||||
impls.insert(TraitImpl::new(
|
||||
class.clone(),
|
||||
impl_trait.clone(),
|
||||
Some(declared_in),
|
||||
declared_in,
|
||||
));
|
||||
} else {
|
||||
ctx.trait_impls().register(
|
||||
impl_trait.qual_name(),
|
||||
set! { TraitImpl::new(class.clone(), impl_trait.clone(), Some(declared_in)) },
|
||||
set! { TraitImpl::new(class.clone(), impl_trait.clone(), declared_in) },
|
||||
);
|
||||
}
|
||||
ctx.methods_list.push(MethodContext::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue