-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Treat empty intersection as 'object', fix intersection simplification #13880
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 |
---|---|---|
|
@@ -148,18 +148,18 @@ fn bindings_ty<'db>( | |
binding, | ||
constraints, | ||
}| { | ||
let mut constraint_tys = | ||
constraints.filter_map(|constraint| narrowing_constraint(db, constraint, binding)); | ||
let mut constraint_tys = constraints | ||
.filter_map(|constraint| narrowing_constraint(db, constraint, binding)) | ||
.peekable(); | ||
|
||
let binding_ty = binding_ty(db, binding); | ||
if let Some(first_constraint_ty) = constraint_tys.next() { | ||
let mut builder = IntersectionBuilder::new(db); | ||
builder = builder | ||
.add_positive(binding_ty) | ||
.add_positive(first_constraint_ty); | ||
for constraint_ty in constraint_tys { | ||
builder = builder.add_positive(constraint_ty); | ||
} | ||
builder.build() | ||
if constraint_tys.peek().is_some() { | ||
constraint_tys | ||
.fold( | ||
IntersectionBuilder::new(db).add_positive(binding_ty), | ||
IntersectionBuilder::add_positive, | ||
) | ||
.build() | ||
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. This is just an unrelated code improvement. No functional change. Let me know if you prefer the old version. 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 the new version is nicer, thank you. Don't know if there is any performance difference, but I'm comfortable leaving that question to experimentation if/when this code is identified as a hot spot in profiling. |
||
} else { | ||
binding_ty | ||
} | ||
|
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.
Without the fix in this PR, I would previously get
Note how the bug only shows up if you add more than one constraint.