Skip to content

Commit 1f745c9

Browse files
committed
[CSSimplify] Skip transitive conformance check if argument is CGFloat
There is an implicit conversion between `CGFloat` and `Double` types so if `CGFloat` argument doesn't satisfy the requirement it's possible that the generic parameter it's passed to be inferred as a `Double` from context and the requirement to be satisfied through this implicit conversion. Resolves: rdar://153461854
1 parent 0999792 commit 1f745c9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9247,6 +9247,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
92479247
if (resolvedTy->isTypeVariableOrMember())
92489248
return formUnsolved();
92499249

9250+
// There is an implicit conversion between `CGFloat` and `Double` types
9251+
// so if `CGFloat` argument doesn't satisfy the requirement it's possible
9252+
// that the generic parameter it's passed to be inferred as a `Double`
9253+
// from context and the requirement to be satisfied through this implicit
9254+
// conversion.
9255+
if (resolvedTy->isCGFloat())
9256+
return SolutionKind::Solved;
9257+
92509258
// If the composition consists of a class + protocol,
92519259
// we can't check conformance of the argument because
92529260
// parameter could pick one of the components.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -debug-constraints -verify %s 2>%t.err
3+
// RUN: %FileCheck %s < %t.err
4+
5+
// REQUIRES: objc_interop
6+
7+
// rdar://153461854
8+
9+
import CoreGraphics
10+
11+
// There is no better way to check this at the moment because diagnostic mode would produce
12+
// a valid solution for this example. We need to make sure that the solution is produced in
13+
// normal mode instead.
14+
15+
let _ = { (point: CGFloat) in
16+
let _: SIMD2<Double>? = SIMD2(point, point)
17+
}
18+
19+
// CHECK-NOT: failed constraint CGFloat transitive conformance to SIMDScalar
20+
// CHECK-NOT: Attempting to salvage

0 commit comments

Comments
 (0)