|
| 1 | +// RUN: %target-swift-emit-silgen %s -verify |
| 2 | + |
| 3 | +func SR12723_thin(_: (@convention(thin) () -> Void) -> Void) {} |
| 4 | +func SR12723_block(_: (@convention(block) () -> Void) -> Void) {} |
| 5 | +func SR12723_c(_: (@convention(c) () -> Void) -> Void) {} |
| 6 | + |
| 7 | +func SR12723_function(_: () -> Void) {} |
| 8 | + |
| 9 | +func context() { |
| 10 | + SR12723_c(SR12723_function) |
| 11 | + |
| 12 | + SR12723_block(SR12723_function) |
| 13 | + |
| 14 | + SR12723_thin(SR12723_function) |
| 15 | +} |
| 16 | + |
| 17 | +struct SR12723_C { |
| 18 | + let function: (@convention(c) () -> Void) -> Void |
| 19 | +} |
| 20 | + |
| 21 | +struct SR12723_Thin { |
| 22 | + let function: (@convention(thin) () -> Void) -> Void |
| 23 | +} |
| 24 | + |
| 25 | +struct SR12723_Block { |
| 26 | + let function: (@convention(block) () -> Void) -> Void |
| 27 | +} |
| 28 | + |
| 29 | +func proxy(_ f: (() -> Void) -> Void) { |
| 30 | + let a = 1 |
| 31 | + f { print(a) } |
| 32 | +} |
| 33 | + |
| 34 | +func cContext() { |
| 35 | + let c = SR12723_C { app in app() } |
| 36 | + |
| 37 | + proxy(c.function) |
| 38 | + // expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to expected argument type '(() -> Void) -> Void'}} |
| 39 | + |
| 40 | + let _ : (@convention(block) () -> Void) -> Void = c.function |
| 41 | + // expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to specified type '(@convention(block) () -> Void) -> Void'}} |
| 42 | + |
| 43 | + let _ : (@convention(c) () -> Void) -> Void = c.function // OK |
| 44 | + |
| 45 | + let _ : (@convention(thin) () -> Void) -> Void = c.function |
| 46 | + // expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to specified type '(@convention(thin) () -> Void) -> Void'}} |
| 47 | + |
| 48 | + let _ : (() -> Void) -> Void = c.function |
| 49 | + // expected-error@-1 {{cannot convert value of type '(@convention(c) () -> Void) -> Void' to specified type '(() -> Void) -> Void'}} |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +func thinContext() { |
| 54 | + let thin = SR12723_Thin { app in app() } |
| 55 | + |
| 56 | + proxy(thin.function) |
| 57 | + // expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to expected argument type '(() -> Void) -> Void'}} |
| 58 | + |
| 59 | + let _ : (@convention(block) () -> Void) -> Void = thin.function |
| 60 | + // expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to specified type '(@convention(block) () -> Void) -> Void'}} |
| 61 | + |
| 62 | + let _ : (@convention(c) () -> Void) -> Void = thin.function |
| 63 | + // expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to specified type '(@convention(c) () -> Void) -> Void'}} |
| 64 | + |
| 65 | + let _ : (@convention(thin) () -> Void) -> Void = thin.function // OK |
| 66 | + |
| 67 | + let _ : (() -> Void) -> Void = thin.function |
| 68 | + // expected-error@-1 {{cannot convert value of type '(@convention(thin) () -> Void) -> Void' to specified type '(() -> Void) -> Void'}} |
| 69 | +} |
| 70 | + |
| 71 | +func blockContext() { |
| 72 | + let block = SR12723_Block { app in app() } |
| 73 | + |
| 74 | + proxy(block.function) |
| 75 | + |
| 76 | + let _ : (@convention(block) () -> Void) -> Void = block.function // OK |
| 77 | + |
| 78 | + let _ : (@convention(c) () -> Void) -> Void = block.function // OK |
| 79 | + |
| 80 | + let _ : (@convention(thin) () -> Void) -> Void = block.function // OK |
| 81 | + |
| 82 | + let _ : (() -> Void) -> Void = block.function // OK |
| 83 | +} |
0 commit comments