Skip to content

Commit 30a1691

Browse files
authored
Merge pull request #60122 from xedin/rdar-95992916
[CSSolver] Don't skip generic overloads when non-generic one has SK_U…
2 parents 1663b1d + baf94c6 commit 30a1691

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/Sema/CSStep.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,11 @@ class DisjunctionStep final : public BindingStep<DisjunctionChoiceProducer> {
702702
// non-generic score indicates that there were no forced
703703
// unwrappings of optional(s), no unavailable overload
704704
// choices present in the solution, no fixes required,
705-
// and there are no non-trivial function conversions.
705+
// and there are no non-trivial user or function conversions.
706706
auto &score = BestNonGenericScore->Data;
707707
return (score[SK_ForceUnchecked] == 0 && score[SK_Unavailable] == 0 &&
708-
score[SK_Fix] == 0 && score[SK_FunctionConversion] == 0);
708+
score[SK_Fix] == 0 && score[SK_UserConversion] == 0 &&
709+
score[SK_FunctionConversion] == 0);
709710
}
710711

711712
/// Attempt to apply given disjunction choice to constraint system.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-emit-silgen %s -verify | %FileCheck %s
2+
3+
// rdar://95992916 - SILGen crash due to incorrect overload pick for `==`
4+
5+
enum E : String {
6+
case a
7+
case b
8+
}
9+
10+
protocol P : AnyObject {
11+
var prop: E { get }
12+
}
13+
14+
func test(arr: [any P]) {
15+
_ = arr.map {
16+
let v = (a: $0.prop, b: $0.prop)
17+
switch v {
18+
case let (a, b) where a == b: break
19+
default: break
20+
}
21+
}
22+
}
23+
24+
// CHECK: sil private [ossa] @$s34anyhashable_and_operator_filtering4test3arrySayAA1P_pG_tFyAaD_pXEfU_
25+
// CHECK: [[LHS_ARG:%.*]] = alloc_stack $E
26+
// CHECK: [[RHS_ARG:%.*]] = alloc_stack $E
27+
// CHECK: function_ref == infix<A>(_:_:)
28+
// CHECK-NEXT: [[GENERIC_OP:%.*]] = function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF : $@convention(thin) <τ_0_0 where τ_0_0 : RawRepresentable, τ_0_0.RawValue : Equatable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> Bool
29+
// CHECK-NEXT: apply [[GENERIC_OP]]<E>([[LHS_ARG]], [[RHS_ARG]])

0 commit comments

Comments
 (0)