-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Preserve qualifiers when accessing attributes on unions/intersections #20114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3309,19 +3309,14 @@ impl<'db> Type<'db> { | |||||||||
let name_str = name.as_str(); | ||||||||||
|
||||||||||
match self { | ||||||||||
Type::Union(union) => union | ||||||||||
.map_with_boundness(db, |elem| { | ||||||||||
elem.member_lookup_with_policy(db, name_str.into(), policy) | ||||||||||
.place | ||||||||||
}) | ||||||||||
.into(), | ||||||||||
Type::Union(union) => union.map_with_boundness_and_qualifiers(db, |elem| { | ||||||||||
elem.member_lookup_with_policy(db, name_str.into(), policy) | ||||||||||
}), | ||||||||||
|
||||||||||
Type::Intersection(intersection) => intersection | ||||||||||
.map_with_boundness(db, |elem| { | ||||||||||
.map_with_boundness_and_qualifiers(db, |elem| { | ||||||||||
elem.member_lookup_with_policy(db, name_str.into(), policy) | ||||||||||
.place | ||||||||||
}) | ||||||||||
.into(), | ||||||||||
}), | ||||||||||
|
||||||||||
Type::Dynamic(..) | Type::Never => Place::bound(self).into(), | ||||||||||
|
||||||||||
|
@@ -9743,21 +9738,20 @@ impl<'db> IntersectionType<'db> { | |||||||||
let mut builder = IntersectionBuilder::new(db); | ||||||||||
let mut qualifiers = TypeQualifiers::empty(); | ||||||||||
|
||||||||||
let mut any_unbound = false; | ||||||||||
let mut any_possibly_unbound = false; | ||||||||||
let mut all_unbound = true; | ||||||||||
let mut any_definitely_bound = false; | ||||||||||
Comment on lines
+9741
to
+9742
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation here now follows |
||||||||||
for ty in self.positive_elements_or_object(db) { | ||||||||||
let PlaceAndQualifiers { | ||||||||||
place: member, | ||||||||||
qualifiers: new_qualifiers, | ||||||||||
} = transform_fn(&ty); | ||||||||||
qualifiers |= new_qualifiers; | ||||||||||
match member { | ||||||||||
Place::Unbound => { | ||||||||||
any_unbound = true; | ||||||||||
} | ||||||||||
Place::Unbound => {} | ||||||||||
Place::Type(ty_member, member_boundness) => { | ||||||||||
if member_boundness == Boundness::PossiblyUnbound { | ||||||||||
any_possibly_unbound = true; | ||||||||||
all_unbound = false; | ||||||||||
if member_boundness == Boundness::Bound { | ||||||||||
any_definitely_bound = true; | ||||||||||
} | ||||||||||
Comment on lines
+9753
to
9755
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I prefer what we have in terms of readability. Not sure if it compiles to worse code (probably not?), but this is not a hot code path anyway. |
||||||||||
|
||||||||||
builder = builder.add_positive(ty_member); | ||||||||||
|
@@ -9766,15 +9760,15 @@ impl<'db> IntersectionType<'db> { | |||||||||
} | ||||||||||
|
||||||||||
PlaceAndQualifiers { | ||||||||||
place: if any_unbound { | ||||||||||
place: if all_unbound { | ||||||||||
Place::Unbound | ||||||||||
} else { | ||||||||||
Place::Type( | ||||||||||
builder.build(), | ||||||||||
if any_possibly_unbound { | ||||||||||
Boundness::PossiblyUnbound | ||||||||||
} else { | ||||||||||
if any_definitely_bound { | ||||||||||
Boundness::Bound | ||||||||||
} else { | ||||||||||
Boundness::PossiblyUnbound | ||||||||||
}, | ||||||||||
) | ||||||||||
}, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly surprised that there was no TODO here. This looks fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this looks fine!