|
| 1 | +// RUN: %swift -typecheck -verify -target %target-cpu-apple-macosx12 %s |
| 2 | +// REQUIRES: OS=macosx |
| 3 | + |
| 4 | + |
| 5 | +protocol P { } |
| 6 | +extension Int: P { } |
| 7 | + |
| 8 | +protocol P1<A, B> { |
| 9 | + associatedtype A |
| 10 | + |
| 11 | + @available(macOS 13, *) |
| 12 | + associatedtype B: P |
| 13 | +} |
| 14 | + |
| 15 | +@available(macOS 13, *) |
| 16 | +struct ModelP1<A, B: P>: P1 { |
| 17 | +} |
| 18 | + |
| 19 | +// Associated types in where clauses |
| 20 | +func testWhereBad<T: P1, U>(_: T) where T.B == U { } |
| 21 | +// expected-error@-1{{'B' is only available in macOS 13 or newer}} |
| 22 | +// expected-note@-2{{add @available attribute to enclosing global function}} |
| 23 | + |
| 24 | +@available(macOS 13, *) |
| 25 | +func testWhereGood<T: P1, U>(_: T) where T.B == U { } |
| 26 | + |
| 27 | +// Associated types in opaque parameter position |
| 28 | +func testPrimaryOpaqueParamBad<U>(_: some P1<some Any, U>) {} |
| 29 | +// expected-error@-1 2{{'B' is only available in macOS 13 or newer}} |
| 30 | +// expected-note@-2 2{{add @available attribute to enclosing global function}} |
| 31 | + |
| 32 | +@available(macOS 13, *) |
| 33 | +func testPrimaryOpaqueParamGood<U: P>(_: some P1<some Any, U>) {} |
| 34 | + |
| 35 | +// Associated types in opaque result position |
| 36 | +func testPrimaryOpaqueResultBad<U: P>() -> some P1<String, U> { |
| 37 | +// expected-error@-1{{'B' is only available in macOS 13 or newer}} |
| 38 | +// expected-note@-2 2{{add @available attribute to enclosing global function}} |
| 39 | + return ModelP1<String, U>() |
| 40 | + // expected-error@-1{{'ModelP1' is only available in macOS 13 or newer}} |
| 41 | + // expected-note@-2{{add 'if #available' version check}} |
| 42 | +} |
| 43 | + |
| 44 | +@available(macOS 13, *) |
| 45 | +func testPrimaryOpaqueResultGood<U: P>() -> some P1<String, U> { |
| 46 | + return ModelP1<String, U>() |
| 47 | +} |
| 48 | + |
| 49 | +// Associated types in existentials |
| 50 | +func testPrimaryExistentialBad<U>(_: any P1<Int, U>) {} |
| 51 | +// expected-error@-1{{'B' is only available in macOS 13 or newer}} |
| 52 | +// expected-note@-2{{add @available attribute to enclosing global function}} |
| 53 | + |
| 54 | +@available(macOS 13, *) |
| 55 | +func testPrimaryExistentialGood<U>(_: any P1<Int, U>) {} |
0 commit comments