diff --git a/lib/Sema/CSStep.h b/lib/Sema/CSStep.h index 5417e80a041..d3d549efad6 100644 --- a/lib/Sema/CSStep.h +++ b/lib/Sema/CSStep.h @@ -702,10 +702,11 @@ private: // non-generic score indicates that there were no forced // unwrappings of optional(s), no unavailable overload // choices present in the solution, no fixes required, - // and there are no non-trivial function conversions. + // and there are no non-trivial user or function conversions. auto &score = BestNonGenericScore->Data; return (score[SK_ForceUnchecked] == 0 && score[SK_Unavailable] == 0 && - score[SK_Fix] == 0 && score[SK_FunctionConversion] == 0); + score[SK_Fix] == 0 && score[SK_UserConversion] == 0 && + score[SK_FunctionConversion] == 0); } /// Attempt to apply given disjunction choice to constraint system. diff --git a/test/Constraints/anyhashable_and_operator_filtering.swift b/test/Constraints/anyhashable_and_operator_filtering.swift new file mode 100644 index 00000000000..17ae1d9da52 --- /dev/null +++ b/test/Constraints/anyhashable_and_operator_filtering.swift @@ -0,0 +1,29 @@ +// RUN: %target-swift-emit-silgen %s -verify | %FileCheck %s + +// rdar://95992916 - SILGen crash due to incorrect overload pick for `==` + +enum E : String { +case a +case b +} + +protocol P : AnyObject { + var prop: E { get } +} + +func test(arr: [any P]) { + _ = arr.map { + let v = (a: $0.prop, b: $0.prop) + switch v { + case let (a, b) where a == b: break + default: break + } + } +} + +// CHECK: sil private [ossa] @$s34anyhashable_and_operator_filtering4test3arrySayAA1P_pG_tFyAaD_pXEfU_ +// CHECK: [[LHS_ARG:%.*]] = alloc_stack $E +// CHECK: [[RHS_ARG:%.*]] = alloc_stack $E +// CHECK: function_ref == infix(_:_:) +// 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 +// CHECK-NEXT: apply [[GENERIC_OP]]([[LHS_ARG]], [[RHS_ARG]])