@@ -86,3 +86,90 @@ struct DeferBody {
8686 // expected-error@-1 {{'No' is unavailable}}
8787 }
8888}
89+
90+ // Ensure that we do not select the unavailable failable init as the
91+ // only solution and then fail to typecheck.
92+ protocol P { }
93+
94+ class C : P {
95+ @available ( swift, obsoleted: 4 )
96+ public init ? ( _ c: C ) {
97+ }
98+
99+ public init < T : P > ( _ c: T ) { }
100+ }
101+
102+ func f( c: C ) {
103+ let _: C ? = C ( c)
104+ }
105+
106+ // rdar://problem/60047439 - unable to disambiguate expression based on availability
107+ func test_contextual_member_with_availability( ) {
108+ struct A {
109+ static var foo : A = A ( )
110+ }
111+
112+ struct B {
113+ @available ( * , unavailable, renamed: " bar " )
114+ static var foo : B = B ( )
115+ }
116+
117+ struct Test {
118+ init ( _: A ) { }
119+ init ( _: B ) { }
120+ }
121+
122+ _ = Test ( . foo) // Ok
123+ }
124+
125+ @available ( * , unavailable)
126+ func unavailableFunction( _ x: Int ) -> Bool { true } // expected-note {{'unavailableFunction' has been explicitly marked unavailable here}}
127+
128+ /// https://github.com/apple/swift/issues/55700
129+ /// Availability checking not working in the `where` clause of a `for` loop
130+ func f_55700( _ arr: [ Int ] ) {
131+ for x in arr where unavailableFunction ( x) { } // expected-error {{'unavailableFunction' is unavailable}}
132+ }
133+
134+ // rdar://101814209
135+ public struct Box < T> {
136+ @usableFromInline
137+ let value : T
138+ }
139+
140+ @available ( macOS, unavailable)
141+ extension Box where T == Int {
142+ @usableFromInline
143+ init ( value: T ) {
144+ self . value = value
145+ }
146+ }
147+
148+ @available ( macOS, unavailable)
149+ @_alwaysEmitIntoClient public func aeicFunction( ) {
150+ // Select the unavailable @usableFromInline init over the synthesized internal
151+ // memberwise initializer.
152+ _ = Box ( value: 42 )
153+ }
154+
155+ // rdar://87403752 - ambiguity with member declared in unavailable extension
156+ struct HasUnavailableExtesion {
157+ }
158+
159+ @available ( * , unavailable)
160+ extension HasUnavailableExtesion {
161+ static var foo : Self = HasUnavailableExtesion ( )
162+ }
163+
164+ func test_contextual_member_with_unavailable_extension( ) {
165+ struct A {
166+ static var foo : A = A ( )
167+ }
168+
169+ struct Test {
170+ init ( _: A ) { }
171+ init ( _: HasUnavailableExtesion ) { }
172+ }
173+
174+ _ = Test ( . foo) // Ok `A.foo` since `foo` from `HasUnavailableExtesion` is unavailable
175+ }
0 commit comments