Skip to content

Commit 8381f01

Browse files
authored
Merge pull request #69331 from xedin/dont-favor-vars-with-no-direct-bindings
[CSBindings] Don't priorize variables without direct bindings over di…
2 parents 61daca9 + 0f194f4 commit 8381f01

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,10 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
10801080
return boundType->lookThroughAllOptionalTypes()->is<TypeVariableType>();
10811081
}
10821082

1083+
// Don't prioritize type variables that don't have any direct bindings.
1084+
if (Bindings.empty())
1085+
return false;
1086+
10831087
return !involvesTypeVariables();
10841088
}
10851089

test/Constraints/casts.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ func test_compatibility_coercions(_ arr: [Int], _ optArr: [Int]?, _ dict: [Strin
349349
_ = [i: stringAnyDict] as [String: Any] // expected-error {{cannot convert value of type 'Int' to expected dictionary key type 'String'}}
350350

351351
// These are currently not peepholed.
352-
_ = [i].self as Magic as [String] // expected-warning {{coercion from '[Int]' to '[String]' may fail; use 'as?' or 'as!' instead}}
353-
_ = (try [i]) as Magic as [String] // expected-warning {{coercion from '[Int]' to '[String]' may fail; use 'as?' or 'as!' instead}}
352+
_ = [i].self as Magic as [String] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
353+
_ = (try [i]) as Magic as [String] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
354354
// expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}
355355

356356
// These are wrong, but make sure we don't warn about the value cast always succeeding.
@@ -750,4 +750,4 @@ do {
750750
_ = a is Issue68825 // expected-error {{cannot find type 'Issue68825' in scope}}
751751
_ = a is String // OK
752752
}
753-
}
753+
}

test/SILGen/collection_downcast.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,4 @@ func testCollectionCompatibilityCoercions(_ arr: [Int], _ optArr: [Any]?, _ set:
297297
// CHECK: [[CAST_FN:%.+]] = function_ref @$ss17_dictionaryUpCastySDyq0_q1_GSDyxq_GSHRzSHR0_r2_lF : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
298298
// CHECK: apply [[CAST_FN]]<String, Int, Int, String>([[DICT]]) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
299299
_ = promote(promote(promote(dict))) as [Int: String]
300-
301-
typealias Magic<T> = T
302-
303-
// These are currently not peepholed.
304-
// CHECK: [[CAST_FN:%.+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
305-
// CHECK: apply [[CAST_FN]]<Int, String>
306-
[i].self as Magic as [String]
307-
308-
// CHECK: [[CAST_FN:%.+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
309-
// CHECK: apply [[CAST_FN]]<Int, String>
310-
(try [i]) as Magic as [String]
311300
}

0 commit comments

Comments
 (0)