Skip to content

[Sema] Fix errors on async when checking only the API availability #40489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange,
ASTContext &ctx = ReferenceDC->getASTContext();
if (ctx.LangOpts.DisableAvailabilityChecking)
return;

if (!shouldCheckAvailability(ReferenceDC->getAsDecl()))
return;

auto runningOS =
TypeChecker::overApproximateAvailabilityAtLocation(
Expand Down
9 changes: 8 additions & 1 deletion test/Sema/api-availability-only-ok.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

// 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
// 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
// RUN: %target-swift-frontend -typecheck-module-from-interface %t/main.swiftinterface

// REQUIRES: OS=macosx
Expand Down Expand Up @@ -102,3 +102,10 @@ public struct Struct {
newFunc()
}
}

internal func asyncFunc() async -> InternalActor {
fatalError()
}

actor InternalActor {
}
23 changes: 22 additions & 1 deletion test/Sema/api-availability-only.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Test that -check-api-availability-only skips what is expected while checking
/// the module API and SPI.

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

/// The flag -check-api-availability-only should reject builds going up to IR and further.
// RUN: not %target-build-swift -emit-executable %s -g -o %t -emit-module -Xfrontend -check-api-availability-only 2>&1 | %FileCheck %s
Expand Down Expand Up @@ -132,3 +132,24 @@ public struct Struct {
extension NewProto { // expected-error {{'NewProto' is only available in macOS 11.0 or newer}}
public func foo() {}
}

func asyncFunc() async -> Bool {
fatalError()
}

// expected-note @+1 {{add @available attribute to enclosing}}
public func publicAsyncFunc() async -> Bool { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
fatalError()
}

// expected-note @+1 {{add @available attribute to enclosing}}
@usableFromInline func usableFromInlineAsyncFunc() async -> Bool { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
fatalError()
}

actor InternalActor {
}

// expected-note @+1 {{add @available attribute to enclosing}}
public actor PublicActor { // expected-error {{concurrency is only available in macOS 10.15.0 or newer}}
}