Skip to content

Commit 94d1897

Browse files
committed
Fix attribute access on intersection types
1 parent 2218db4 commit 94d1897

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,19 +3309,14 @@ impl<'db> Type<'db> {
33093309
let name_str = name.as_str();
33103310

33113311
match self {
3312-
Type::Union(union) => union
3313-
.map_with_boundness(db, |elem| {
3314-
elem.member_lookup_with_policy(db, name_str.into(), policy)
3315-
.place
3316-
})
3317-
.into(),
3312+
Type::Union(union) => union.map_with_boundness_and_qualifiers(db, |elem| {
3313+
elem.member_lookup_with_policy(db, name_str.into(), policy)
3314+
}),
33183315

33193316
Type::Intersection(intersection) => intersection
3320-
.map_with_boundness(db, |elem| {
3317+
.map_with_boundness_and_qualifiers(db, |elem| {
33213318
elem.member_lookup_with_policy(db, name_str.into(), policy)
3322-
.place
3323-
})
3324-
.into(),
3319+
}),
33253320

33263321
Type::Dynamic(..) | Type::Never => Place::bound(self).into(),
33273322

@@ -9747,21 +9742,20 @@ impl<'db> IntersectionType<'db> {
97479742
let mut builder = IntersectionBuilder::new(db);
97489743
let mut qualifiers = TypeQualifiers::empty();
97499744

9750-
let mut any_unbound = false;
9751-
let mut any_possibly_unbound = false;
9745+
let mut all_unbound = false;
9746+
let mut any_definitely_bound = false;
97529747
for ty in self.positive_elements_or_object(db) {
97539748
let PlaceAndQualifiers {
97549749
place: member,
97559750
qualifiers: new_qualifiers,
97569751
} = transform_fn(&ty);
97579752
qualifiers |= new_qualifiers;
97589753
match member {
9759-
Place::Unbound => {
9760-
any_unbound = true;
9761-
}
9754+
Place::Unbound => {}
97629755
Place::Type(ty_member, member_boundness) => {
9763-
if member_boundness == Boundness::PossiblyUnbound {
9764-
any_possibly_unbound = true;
9756+
all_unbound = false;
9757+
if member_boundness == Boundness::Bound {
9758+
any_definitely_bound = true;
97659759
}
97669760

97679761
builder = builder.add_positive(ty_member);
@@ -9770,15 +9764,15 @@ impl<'db> IntersectionType<'db> {
97709764
}
97719765

97729766
PlaceAndQualifiers {
9773-
place: if any_unbound {
9767+
place: if all_unbound {
97749768
Place::Unbound
97759769
} else {
97769770
Place::Type(
97779771
builder.build(),
9778-
if any_possibly_unbound {
9779-
Boundness::PossiblyUnbound
9780-
} else {
9772+
if any_definitely_bound {
97819773
Boundness::Bound
9774+
} else {
9775+
Boundness::PossiblyUnbound
97829776
},
97839777
)
97849778
},

0 commit comments

Comments
 (0)