Skip to content

Commit 34e6473

Browse files
authored
Merge pull request #82070 from slavapestov/test-rdar152700122
Add regression test for rdar://152700122
2 parents 6c9a8b4 + 7c78224 commit 34e6473

File tree

61 files changed

+105
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+105
-89
lines changed

test/Sema/availability.swift renamed to test/Availability/availability.swift

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

test/Constraints/operator_availability.swift renamed to test/Availability/operator_availability.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ func testAvailability() {
2929
_ = (1 as Int32) <=< (1 as Int32) // okay
3030
_ = (1 as Int32) >=> (1 as Int32) // expected-error{{'>=>' is unavailable}}
3131
}
32+
33+
// rdar://problem/152700122
34+
infix operator ~>
35+
public func ~><T> (lhs: T, rhs: (T) -> Void) -> T {
36+
fatalError()
37+
}
38+
39+
struct S {
40+
@available(macOS 20, *)
41+
func f() {}
42+
}
43+
44+
let s = S() ~> {
45+
if #available(macOS 20.0, *) {
46+
$0.f()
47+
}
48+
}

test/Constraints/availability.swift

Lines changed: 0 additions & 88 deletions
This file was deleted.

test/Misc/verify-swift-feature-testing.test-sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ EXCEPTIONAL_FILES = [
2020
# Tests for ModuleInterfaceExportAs being ignored
2121
pathlib.Path("test/ModuleInterface/swift-export-as.swift"),
2222
# Uses the pseudo-feature AvailabilityMacro=
23-
pathlib.Path("test/Sema/availability_define.swift"),
23+
pathlib.Path("test/Availability/availability_define.swift"),
2424
# Tests behavior when you try to use a feature without enabling it
2525
pathlib.Path("test/attr/feature_requirement.swift"),
2626
# Tests completion with features both enabled and disabled

0 commit comments

Comments
 (0)