Skip to content

Commit

Permalink
fix: intersection type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Nov 14, 2024
1 parent b840198 commit 8f2936b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/erg_compiler/context/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ impl Context {
}
if l.len() == r.len() {
let mut r = r.clone();
for _ in 1..l.len() {
for _ in 0..r.len() {
if l.iter().zip(&r).all(|(l, r)| self.supertype_of(l, r)) {
return true;
}
Expand Down
14 changes: 0 additions & 14 deletions crates/erg_compiler/context/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,27 +1401,13 @@ impl Context {
/// This is needed because the trait implementation spec can contain projection types.
/// e.g. `Tuple(Ts) <: Container(Ts.union())`
fn poly_class_trait_impl_exists(&self, class: &Type, trait_: &Type) -> bool {
let class_hash = get_hash(&class);
let trait_hash = get_hash(&trait_);
for imp in self.get_trait_impls(trait_).into_iter() {
let _sub_subs = Substituter::substitute_typarams(self, &imp.sub_type, class).ok();
let _sup_subs = Substituter::substitute_typarams(self, &imp.sup_trait, trait_).ok();
if self.supertype_of(&imp.sub_type, class) && self.supertype_of(&imp.sup_trait, trait_)
{
if class_hash != get_hash(&class) {
class.undo();
}
if trait_hash != get_hash(&trait_) {
trait_.undo();
}
return true;
}
if class_hash != get_hash(&class) {
class.undo();
}
if trait_hash != get_hash(&trait_) {
trait_.undo();
}
}
false
}
Expand Down
9 changes: 9 additions & 0 deletions crates/erg_compiler/context/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ impl Context {
expected: &Type,
found: &Type,
) -> Option<String> {
if self.cfg.fast_error_report {
return None;
}
if &callee_t.qual_name()[..] == "List" && attr == Some("__getitem__") && nth == 1 {
let len = &callee_t.typarams().get(1).cloned()?;
let (_, _, pred) = found.clone().deconstruct_refinement().ok()?;
Expand Down Expand Up @@ -73,6 +76,9 @@ impl Context {
expected: &Type,
found: &Type,
) -> Option<String> {
if self.cfg.fast_error_report {
return None;
}
let expected = if let Some(fv) = expected.as_free() {
if fv.is_linked() {
fv.crack().clone()
Expand Down Expand Up @@ -284,6 +290,9 @@ impl Context {
}

pub(crate) fn get_no_candidate_hint(&self, proj: &Type) -> Option<String> {
if self.cfg.fast_error_report {
return None;
}
match proj {
Type::Proj { lhs, rhs: _ } => {
if let Some(fv) = lhs.as_free() {
Expand Down
7 changes: 5 additions & 2 deletions crates/erg_compiler/context/initialize/const_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,12 @@ pub(crate) fn sub_vdict_get<'d>(
if key == k {
return Some(v);
}
match (ctx.convert_value_into_type(key.clone()), ctx.convert_value_into_type(k.clone())) {
match (
ctx.convert_value_into_type(key.clone()),
ctx.convert_value_into_type(k.clone()),
) {
(Ok(idx), Ok(kt))
if ctx.subtype_of(&idx.lower_bounded(), &kt.lower_bounded()) /*|| dict.len() == 1*/ =>
if dict.len() == 1 || ctx.subtype_of(&idx.lower_bounded(), &kt.lower_bounded()) =>
{
matches.push((idx, kt, v));
}
Expand Down

0 comments on commit 8f2936b

Please sign in to comment.