forked from apple/swift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Concurrency] Apply
@preconcurrency
to typealiases at the point of …
…use. When referencing a `@preconcurrency` typealias from code that does not require strict concurrency, strip off `@Sendable` and global actor types. This is consistent with references to functions/properties/etc. that are `@preconcurrency`. Fixes apple#60487, rdar://98343624.
- Loading branch information
1 parent
c0e652b
commit e04f0d7
Showing
2 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %target-swift-frontend -typecheck -verify %s | ||
// REQUIRES: concurrency | ||
|
||
@preconcurrency @MainActor func f() { } | ||
// expected-note@-1 2{{calls to global function 'f()' from outside of its actor context are implicitly asynchronous}} | ||
|
||
@preconcurrency typealias FN = @Sendable () -> Void | ||
|
||
struct Outer { | ||
@preconcurrency typealias FN = @Sendable () -> Void | ||
} | ||
|
||
func test() { | ||
var _: Outer.FN = { | ||
f() | ||
} | ||
|
||
var _: FN = { | ||
f() | ||
print("Hello") | ||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.1, *) | ||
func testAsync() async { | ||
var _: Outer.FN = { | ||
f() // expected-error{{call to main actor-isolated global function 'f()' in a synchronous nonisolated context}} | ||
} | ||
|
||
var _: FN = { | ||
f() // expected-error{{call to main actor-isolated global function 'f()' in a synchronous nonisolated context}} | ||
print("Hello") | ||
} | ||
} |