|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | +// REQUIRES: objc_interop |
| 3 | + |
| 4 | +import Foundation |
| 5 | +import CoreGraphics |
| 6 | + |
| 7 | +///////////// |
| 8 | + |
| 9 | +struct G<T> { // expected-note {{arguments to generic parameter 'T' ('CGFloat?' and 'CGFloat') are expected to be equal}} |
| 10 | + var t: T |
| 11 | +} |
| 12 | + |
| 13 | +func foo1(x: (x: Int, y: Int)?, y: (Int, Int)) -> G<(x: Int, y: Int)> { |
| 14 | + let g = G(t: x ?? y) |
| 15 | + return g |
| 16 | +} |
| 17 | + |
| 18 | +func foo2(x: (Int, Int)?, y: (x: Int, y: Int)) -> G<(Int, Int)> { |
| 19 | + let g = G(t: x ?? y) |
| 20 | + return g |
| 21 | +} |
| 22 | + |
| 23 | +func foo3(x: (@convention(block) () -> ())?, y: @escaping () -> ()) -> G<@convention(block) () -> ()> { |
| 24 | + let g = G(t: x ?? y) |
| 25 | + return g |
| 26 | +} |
| 27 | + |
| 28 | +func foo4(x: (() -> ())?, y: @escaping @convention(block) () -> ()) -> G<() -> ()> { |
| 29 | + let g = G(t: x ?? y) |
| 30 | + return g |
| 31 | +} |
| 32 | + |
| 33 | +func foo5(x: CGFloat?, y: Double) -> G<CGFloat> { |
| 34 | + let g = G(t: x ?? y) |
| 35 | + // FIXME |
| 36 | + return g // expected-error {{cannot convert return expression of type 'G<CGFloat?>' to return type 'G<CGFloat>'}} |
| 37 | +} |
| 38 | + |
| 39 | +func foo6(x: Double?, y: CGFloat) -> G<Double> { |
| 40 | + let g = G(t: x ?? y) |
| 41 | + return g |
| 42 | +} |
| 43 | + |
| 44 | +///////////// |
| 45 | + |
| 46 | +func id<T>(_: T) -> T {} |
| 47 | + |
| 48 | +func bar1(x: (x: Int, y: Int)) { |
| 49 | + func f(_: (Int, Int)) {} |
| 50 | + f(id(x)) |
| 51 | +} |
| 52 | + |
| 53 | +func bar2(x: (Int, Int)) { |
| 54 | + func f(_: (x: Int, y: Int)) {} |
| 55 | + f(id(x)) |
| 56 | +} |
| 57 | + |
| 58 | +func bar3(x: @escaping () -> ()) { |
| 59 | + func f(_: @escaping @convention(block) () -> ()) {} |
| 60 | + // FIXME |
| 61 | + f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('@convention(block) () -> ()' vs. '() -> ()')}} |
| 62 | +} |
| 63 | + |
| 64 | +func bar4(x: @escaping @convention(block) () -> ()) { |
| 65 | + func f(_: @escaping () -> ()) {} |
| 66 | + // FIXME |
| 67 | + f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('() -> ()' vs. '@convention(block) () -> ()')}} |
| 68 | +} |
| 69 | + |
| 70 | +func bar5(x: Double) { |
| 71 | + func f(_: CGFloat) {} |
| 72 | + f(id(x)) |
| 73 | +} |
| 74 | + |
| 75 | +func bar6(x: CGFloat) { |
| 76 | + func f(_: Double) {} |
| 77 | + f(id(x)) |
| 78 | +} |
| 79 | + |
| 80 | +///////////// |
| 81 | + |
| 82 | +func unwrap<T>(_: T?) -> T {} |
| 83 | + |
| 84 | +func baz1(x: (x: Int, y: Int)?) { |
| 85 | + func f(_: (Int, Int)) {} |
| 86 | + f(unwrap(x)) |
| 87 | +} |
| 88 | + |
| 89 | +func baz2(x: (Int, Int)?) { |
| 90 | + func f(_: (x: Int, y: Int)) {} |
| 91 | + f(unwrap(x)) |
| 92 | +} |
| 93 | + |
| 94 | +func baz3(x: (() -> ())?) { |
| 95 | + func f(_: @escaping @convention(block) () -> ()) {} |
| 96 | + f(unwrap(x)) |
| 97 | +} |
| 98 | + |
| 99 | +func baz4(x: (@convention(block) () -> ())?) { |
| 100 | + func f(_: @escaping () -> ()) {} |
| 101 | + f(unwrap(x)) |
| 102 | +} |
| 103 | + |
| 104 | +func baz5(x: Double?) { |
| 105 | + func f(_: CGFloat) {} |
| 106 | + f(unwrap(x)) |
| 107 | +} |
| 108 | + |
| 109 | +func baz6(x: CGFloat?) { |
| 110 | + func f(_: Double) {} |
| 111 | + f(unwrap(x)) |
| 112 | +} |
| 113 | + |
0 commit comments