Skip to content

[CSBindings] New binding formed by join operation should refer to con… #35699

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

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,10 @@ bool PotentialBindings::addPotentialBinding(PotentialBinding binding,
Type::join(existingBinding->BindingType, binding.BindingType);

if (join && isAcceptableJoin(*join)) {
joined.push_back(existingBinding->withType(*join));
// Result of the join has to use new binding because it refers
// to the constraint that triggered the join that replaced the
// existing binding.
joined.push_back(binding.withType(*join));
// Remove existing binding from the set.
// It has to be re-introduced later, since its type has been changed.
existingBinding = Bindings.erase(existingBinding);
Expand Down
11 changes: 11 additions & 0 deletions test/Sema/type_join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ func rdar37241221(_ a: C?, _ b: D?) {
let inferred = [a!, b]
expectEqualType(type(of: array_c_opt).self, type(of: inferred).self)
}

extension FixedWidthInteger {
public static func test_nonstale_join_result<Other: BinaryInteger>(_ lhs: inout Self, _ rhs: Other) {
let shift = rhs < -Self.bitWidth ? -Self.bitWidth
: rhs > Self.bitWidth ? Self.bitWidth
: Int(rhs) // `shift` is `Int`

func accepts_int(_: Int) {}
accepts_int(shift) // Ok
}
}