|
| 1 | +// RUN: %swift -typecheck -verify -target %target-cpu-apple-macosx12 %s |
| 2 | +// REQUIRES: OS=macosx |
| 3 | + |
| 4 | +protocol ProtoWithAssocType { |
| 5 | + associatedtype A // expected-note * {{requirement 'A' declared here}} |
| 6 | +} |
| 7 | + |
| 8 | +struct ConformsToProtoWithAssocType_WitnessOld: ProtoWithAssocType { |
| 9 | + @available(macOS 11, *) |
| 10 | + struct A {} // Ok, A is less available than its parent but more available than the deployment target |
| 11 | +} |
| 12 | + |
| 13 | +struct ConformsToProtoWithAssocType_WitnessSame: ProtoWithAssocType { |
| 14 | + @available(macOS 12, *) |
| 15 | + struct A {} // Ok, A is less available than its parent but available at the deployment target |
| 16 | +} |
| 17 | + |
| 18 | +struct ConformsToProtoWithAssocType_WitnessTooNew: ProtoWithAssocType { |
| 19 | + @available(macOS 13, *) |
| 20 | + struct A {} // expected-warning {{protocol 'ProtoWithAssocType' requires 'A' to be available in macOS 12 and newer; this will be an error in a future Swift language mode}} |
| 21 | +} |
| 22 | + |
| 23 | +struct ConformsToProtoWithAssocTypeInExtension_WitnessOld {} |
| 24 | + |
| 25 | +extension ConformsToProtoWithAssocTypeInExtension_WitnessOld: ProtoWithAssocType { |
| 26 | + @available(macOS 11, *) |
| 27 | + struct A {} // Ok, A is less available than its parent but more available than the deployment target |
| 28 | +} |
| 29 | + |
| 30 | +struct ConformsToProtoWithAssocTypeInExtension_WitnessSame {} |
| 31 | + |
| 32 | +extension ConformsToProtoWithAssocTypeInExtension_WitnessSame: ProtoWithAssocType { |
| 33 | + @available(macOS 12, *) |
| 34 | + struct A {} // Ok, A is less available than its parent but available at the deployment target |
| 35 | +} |
| 36 | + |
| 37 | +struct ConformsToProtoWithAssocTypeInExtension_WitnessTooNew {} |
| 38 | + |
| 39 | +extension ConformsToProtoWithAssocTypeInExtension_WitnessTooNew: ProtoWithAssocType { |
| 40 | + @available(macOS 13, *) |
| 41 | + struct A {} // expected-warning {{protocol 'ProtoWithAssocType' requires 'A' to be available in macOS 12 and newer; this will be an error in a future Swift language mode}} |
| 42 | +} |
| 43 | + |
| 44 | +@available(macOS 13, *) |
| 45 | +struct ConformsToProtoWithAssocType_NewerConformance: ProtoWithAssocType { |
| 46 | + struct A {} // Ok, A is as available as the conformance |
| 47 | +} |
| 48 | + |
| 49 | +struct ConformsToProtoWithAssocTypeInExtension_NewerConformance {} |
| 50 | + |
| 51 | +@available(macOS 13, *) |
| 52 | +extension ConformsToProtoWithAssocTypeInExtension_NewerConformance: ProtoWithAssocType { |
| 53 | + struct A {} // Ok, A is as available as the conformance |
| 54 | +} |
| 55 | + |
| 56 | +@available(macOS 13, *) |
| 57 | +struct ConformsToProtoWithAssocType_NewerAndWitnessTooNew: ProtoWithAssocType { |
| 58 | + @available(macOS 14, *) |
| 59 | + struct A {} // expected-warning {{protocol 'ProtoWithAssocType' requires 'A' to be available in macOS 13 and newer; this will be an error in a future Swift language mode}} |
| 60 | +} |
| 61 | + |
| 62 | +struct ConformsToProtoWithAssocType_WitnessUnavailable: ProtoWithAssocType { |
| 63 | + @available(macOS, unavailable) |
| 64 | + struct A {} // expected-warning {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType'; this will be an error in a future Swift language mode}} |
| 65 | +} |
| 66 | + |
| 67 | +struct ConformsToProtoWithAssocType_WitnessUnavailableInExtension: ProtoWithAssocType { |
| 68 | + // expected-warning@-1 {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType'; this will be an error in a future Swift language mode}} |
| 69 | +} |
| 70 | + |
| 71 | +extension ConformsToProtoWithAssocType_WitnessUnavailableInExtension { |
| 72 | + @available(macOS, unavailable) |
| 73 | + struct A {} // expected-note {{'A' declared here}} |
| 74 | +} |
| 75 | + |
| 76 | +struct ConformsToProtoWithAssocType_WitnessInUnavailableExtension: ProtoWithAssocType { |
| 77 | + // expected-warning@-1 {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType'; this will be an error in a future Swift language mode}} |
| 78 | +} |
| 79 | + |
| 80 | +@available(macOS, unavailable) |
| 81 | +extension ConformsToProtoWithAssocType_WitnessInUnavailableExtension { |
| 82 | + struct A {} // expected-note {{'A' declared here}} |
| 83 | +} |
| 84 | + |
| 85 | +struct ConformsToProtoWithAssocType_WitnessUnavailableMessage: ProtoWithAssocType { |
| 86 | + @available(*, unavailable, message: "Just don't") |
| 87 | + struct A {} // expected-warning {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType': Just don't; this will be an error in a future Swift language mode}} |
| 88 | +} |
| 89 | + |
| 90 | +struct ConformsToProtoWithAssocType_WitnessObsoleted: ProtoWithAssocType { |
| 91 | + @available(macOS, obsoleted: 11) |
| 92 | + struct A {} // expected-warning {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType'; this will be an error in a future Swift language mode}} |
| 93 | +} |
| 94 | + |
| 95 | +struct ConformsToProtoWithAssocType_WitnessIntroInSwift99: ProtoWithAssocType { |
| 96 | + @available(swift, introduced: 99) |
| 97 | + struct A {} // expected-warning {{unavailable struct 'A' was used to satisfy a requirement of protocol 'ProtoWithAssocType'; this will be an error in a future Swift language mode}} |
| 98 | +} |
| 99 | + |
| 100 | +@available(macOS, unavailable) |
| 101 | +struct ConformsToProtoWithAssocType_Unavailable: ProtoWithAssocType { |
| 102 | + struct A {} // Ok, the conformance is unavailable too. |
| 103 | +} |
| 104 | + |
| 105 | +@available(macOS, unavailable) |
| 106 | +struct ConformsToProtoWithAssocType_WitnessAndConformanceUnavailable: ProtoWithAssocType { |
| 107 | + @available(macOS, unavailable) |
| 108 | + struct A {} // Ok, the conformance is unavailable too. |
| 109 | +} |
| 110 | + |
| 111 | +protocol ProtoWithNewAssocType { |
| 112 | + @available(macOS 13, *) |
| 113 | + associatedtype A |
| 114 | +} |
| 115 | + |
| 116 | +struct ConformsToProtoWithNewAssocType_WitnessOld: ProtoWithNewAssocType { |
| 117 | + struct A {} // Ok, A has always been available |
| 118 | +} |
| 119 | + |
| 120 | +struct ConformsToProtoWithNewAssocType_WitnessSame: ProtoWithNewAssocType { |
| 121 | + @available(macOS 13, *) |
| 122 | + struct A {} // Ok, A is as available as the associated type requirement |
| 123 | +} |
| 124 | + |
| 125 | +struct ConformsToProtoWithNewAssocType_WitnessTooNew: ProtoWithNewAssocType { |
| 126 | + @available(macOS 14, *) |
| 127 | + struct A {} // expected-warning {{protocol 'ProtoWithNewAssocType' requires 'A' to be available in macOS 13 and newer; this will be an error in a future Swift language mode}} |
| 128 | +} |
| 129 | + |
| 130 | +protocol ProtoWithAssocTypeAndReq { |
| 131 | + associatedtype A |
| 132 | + |
| 133 | + @available(macOS 13, *) |
| 134 | + func req(_ a: A) |
| 135 | +} |
| 136 | + |
| 137 | +@available(macOS 11, *) |
| 138 | +struct InferredOld {} // Ok, InferredOld is less available than its parent but more available than the deployment target |
| 139 | + |
| 140 | +struct ConformsToProtoWithAssocTypeAndReq_InferredWitnessOld: ProtoWithAssocTypeAndReq { |
| 141 | + |
| 142 | + func req(_ a: InferredOld) {} |
| 143 | +} |
| 144 | + |
| 145 | +@available(macOS 12, *) |
| 146 | +struct InferredSame {} // Ok, InferredSame is less available than its parent but available at the deployment target |
| 147 | + |
| 148 | +struct ConformsToProtoWithAssocTypeAndReq_InferredWitnessSame: ProtoWithAssocTypeAndReq { |
| 149 | + func req(_ a: InferredSame) {} |
| 150 | +} |
| 151 | + |
| 152 | +@available(macOS 13, *) |
| 153 | +struct InferredTooNew {} // expected-note {{'InferredTooNew' declared here}} |
| 154 | + |
| 155 | +struct ConformsToProtoWithAssocTypeAndReq_InferredWitnessTooNew: ProtoWithAssocTypeAndReq { |
| 156 | + // expected-warning@-1 {{protocol 'ProtoWithAssocTypeAndReq' requires 'InferredTooNew' to be available in macOS 12 and newer; this will be an error in a future Swift language mode}} |
| 157 | + |
| 158 | + @available(macOS 13, *) |
| 159 | + func req(_ a: InferredTooNew) {} |
| 160 | +} |
| 161 | + |
| 162 | +@available(macOS, unavailable) |
| 163 | +struct ConformsToProtoWithAssocTypeAndReq_InferredUnavailable: ProtoWithAssocTypeAndReq { |
| 164 | + @available(macOS, unavailable) |
| 165 | + struct InferredUnavailable {} |
| 166 | + |
| 167 | + func req(_ a: InferredUnavailable) {} |
| 168 | +} |
0 commit comments