diff --git a/test/Constraints/bidirectional_conversions.swift b/test/Constraints/bidirectional_conversions.swift new file mode 100644 index 0000000000000..de5077c507a32 --- /dev/null +++ b/test/Constraints/bidirectional_conversions.swift @@ -0,0 +1,113 @@ +// RUN: %target-typecheck-verify-swift +// REQUIRES: objc_interop + +import Foundation +import CoreGraphics + +///////////// + +struct G { // expected-note {{arguments to generic parameter 'T' ('CGFloat?' and 'CGFloat') are expected to be equal}} + var t: T +} + +func foo1(x: (x: Int, y: Int)?, y: (Int, Int)) -> G<(x: Int, y: Int)> { + let g = G(t: x ?? y) + return g +} + +func foo2(x: (Int, Int)?, y: (x: Int, y: Int)) -> G<(Int, Int)> { + let g = G(t: x ?? y) + return g +} + +func foo3(x: (@convention(block) () -> ())?, y: @escaping () -> ()) -> G<@convention(block) () -> ()> { + let g = G(t: x ?? y) + return g +} + +func foo4(x: (() -> ())?, y: @escaping @convention(block) () -> ()) -> G<() -> ()> { + let g = G(t: x ?? y) + return g +} + +func foo5(x: CGFloat?, y: Double) -> G { + let g = G(t: x ?? y) + // FIXME + return g // expected-error {{cannot convert return expression of type 'G' to return type 'G'}} +} + +func foo6(x: Double?, y: CGFloat) -> G { + let g = G(t: x ?? y) + return g +} + +///////////// + +func id(_: T) -> T {} + +func bar1(x: (x: Int, y: Int)) { + func f(_: (Int, Int)) {} + f(id(x)) +} + +func bar2(x: (Int, Int)) { + func f(_: (x: Int, y: Int)) {} + f(id(x)) +} + +func bar3(x: @escaping () -> ()) { + func f(_: @escaping @convention(block) () -> ()) {} + // FIXME + f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('@convention(block) () -> ()' vs. '() -> ()')}} +} + +func bar4(x: @escaping @convention(block) () -> ()) { + func f(_: @escaping () -> ()) {} + // FIXME + f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('() -> ()' vs. '@convention(block) () -> ()')}} +} + +func bar5(x: Double) { + func f(_: CGFloat) {} + f(id(x)) +} + +func bar6(x: CGFloat) { + func f(_: Double) {} + f(id(x)) +} + +///////////// + +func unwrap(_: T?) -> T {} + +func baz1(x: (x: Int, y: Int)?) { + func f(_: (Int, Int)) {} + f(unwrap(x)) +} + +func baz2(x: (Int, Int)?) { + func f(_: (x: Int, y: Int)) {} + f(unwrap(x)) +} + +func baz3(x: (() -> ())?) { + func f(_: @escaping @convention(block) () -> ()) {} + f(unwrap(x)) +} + +func baz4(x: (@convention(block) () -> ())?) { + func f(_: @escaping () -> ()) {} + f(unwrap(x)) +} + +func baz5(x: Double?) { + func f(_: CGFloat) {} + f(unwrap(x)) +} + +func baz6(x: CGFloat?) { + func f(_: Double) {} + f(unwrap(x)) +} + diff --git a/validation-test/Sema/type_checker_perf/fast/swift_docc.swift b/validation-test/Sema/type_checker_perf/fast/swift_docc.swift new file mode 100644 index 0000000000000..e36687f5a3aad --- /dev/null +++ b/validation-test/Sema/type_checker_perf/fast/swift_docc.swift @@ -0,0 +1,35 @@ +// RUN: %target-typecheck-verify-swift -solver-scope-threshold=2000 + +// We don't use anything from Foundation below, but Foundation adds a +// large number of == overloads. Import it if we can, because it makes +// the problem instance harder. +#if canImport(Foundation) +import Foundation +#endif + +struct Graph { + func nodeWithReference(_: Int) -> Node? { fatalError() } +} + +struct DocumentationContext { + func parents(of: Int) -> [Int] { fatalError() } + var topicGraph: Graph +} + +struct Node { + var reference: Int + var kind: Kind + + enum Kind { + case tutorialTableOfContents + case chapter + case volume + } +} + +func analyze(_ node: Node, context: DocumentationContext) { + _ = context.parents(of: node.reference) + .compactMap({ context.topicGraph.nodeWithReference($0) }) + .first(where: { $0.kind == .tutorialTableOfContents || $0.kind == .chapter || $0.kind == .volume }) +} +