Skip to content

Commit 3475200

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 3475200

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// rdar://153461854
6+
7+
import CoreGraphics
8+
9+
// There is no better way to check this at the moment because diagnostic mode would produce
10+
// a valid solution for this example. We need to make sure that the solution is produced in
11+
// normal mode instead.
12+
13+
let _ = { (point: CGFloat) in
14+
let _: SIMD2<Double>? = SIMD2(point, point)
15+
}
16+
17+
// CHECK-NOT: failed constraint CGFloat transitive conformance to SIMDScalar
18+
// CHECK-NOT: Attempting to salvage

0 commit comments

Comments
 (0)