Skip to content

Commit 69ee427

Browse files
committed
[Sema] Fix reports on async when checking only the API availability
-check-api-availability-only limits availability checking to the API only, ensuring that was will appear in the swiftinterface is sound but without raising issues about implementation details. This patch ensures it correctly ignore non-public async functions as they wouldn't appear in the API. rdar://86174644
1 parent eda3824 commit 69ee427

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,9 @@ void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange,
17101710
ASTContext &ctx = ReferenceDC->getASTContext();
17111711
if (ctx.LangOpts.DisableAvailabilityChecking)
17121712
return;
1713+
1714+
if (!shouldCheckAvailability(ReferenceDC->getAsDecl()))
1715+
return;
17131716

17141717
auto runningOS =
17151718
TypeChecker::overApproximateAvailabilityAtLocation(

test/Sema/api-availability-only-ok.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// RUN: %empty-directory(%t)
55

6-
// RUN: %swiftc_driver -emit-module %s -target %target-cpu-apple-macosx10.15 -emit-module-interface -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution -check-api-availability-only -verify-emitted-module-interface
6+
// RUN: %swiftc_driver -emit-module %s -target %target-cpu-apple-macosx10.14 -emit-module-interface -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution -check-api-availability-only -verify-emitted-module-interface
77
// RUN: %target-swift-frontend -typecheck-module-from-interface %t/main.swiftinterface
88

99
// REQUIRES: OS=macosx
@@ -102,3 +102,10 @@ public struct Struct {
102102
newFunc()
103103
}
104104
}
105+
106+
internal func asyncFunc() async -> InternalActor {
107+
fatalError()
108+
}
109+
110+
actor InternalActor {
111+
}

test/Sema/api-availability-only.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Test that -check-api-availability-only skips what is expected while checking
22
/// the module API and SPI.
33

4-
// RUN: %target-typecheck-verify-swift -module-name MyModule -target %target-cpu-apple-macosx10.15 -check-api-availability-only -enable-library-evolution
4+
// RUN: %target-typecheck-verify-swift -module-name MyModule -target %target-cpu-apple-macosx10.14 -check-api-availability-only -enable-library-evolution
55

66
/// The flag -check-api-availability-only should reject builds going up to IR and further.
77
// RUN: not %target-build-swift -emit-executable %s -g -o %t -emit-module -Xfrontend -check-api-availability-only 2>&1 | %FileCheck %s
@@ -132,3 +132,24 @@ public struct Struct {
132132
extension NewProto { // expected-error {{'NewProto' is only available in macOS 11.0 or newer}}
133133
public func foo() {}
134134
}
135+
136+
func asyncFunc() async -> Bool {
137+
fatalError()
138+
}
139+
140+
// expected-note @+1 {{add @available attribute to enclosing}}
141+
public func publicAsyncFunc() async -> Bool { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
142+
fatalError()
143+
}
144+
145+
// expected-note @+1 {{add @available attribute to enclosing}}
146+
@usableFromInline func usableFromInlineAsyncFunc() async -> Bool { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
147+
fatalError()
148+
}
149+
150+
actor InternalActor {
151+
}
152+
153+
// expected-note @+1 {{add @available attribute to enclosing}}
154+
public actor PublicActor { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
155+
}

0 commit comments

Comments
 (0)