Skip to content

[CSSimplify] Skip transitive conformance check if argument is CGFloat or Double #82541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9247,6 +9247,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
if (resolvedTy->isTypeVariableOrMember())
return formUnsolved();

// There is an implicit conversion between `CGFloat` and `Double` types
// so if `CGFloat`/`Double` argument doesn't satisfy the requirement it's
// possible that the generic parameter it's passed to be inferred as a
// the other type from context and the requirement to be satisfied through
// this implicit conversion.
if (resolvedTy->isCGFloat() || resolvedTy->isDouble())
return SolutionKind::Solved;

// If the composition consists of a class + protocol,
// we can't check conformance of the argument because
// parameter could pick one of the components.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -debug-constraints -verify %s 2>%t.err
// RUN: %FileCheck %s < %t.err

// REQUIRES: objc_interop

// rdar://153461854

import CoreGraphics

// There is no better way to check this at the moment because diagnostic mode would produce
// a valid solution for this example. We need to make sure that the solution is produced in
// normal mode instead.

let _ = { (point: CGFloat) in
let _: SIMD2<Double>? = SIMD2(point, point)
}

// CHECK-NOT: failed constraint CGFloat transitive conformance to SIMDScalar
// CHECK-NOT: Attempting to salvage

protocol P {}
extension CGFloat: P {}

struct S<T> {}

func foo<T: P>(_ x: T) -> S<T> { .init() }

_ = { (x: Double) in
let _: S<CGFloat> = foo(x)
}

// CHECK-NOT: failed constraint CGFloat transitive conformance to SIMDScalar
// CHECK-NOT: Attempting to salvage