Skip to content

[TaskLocals] dont crash checking for taskgroup when in no task #37681

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 1 commit into from
Jun 8, 2021
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
5 changes: 5 additions & 0 deletions stdlib/public/Concurrency/TaskStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ SWIFT_CC(swift)
static bool swift_task_hasTaskGroupStatusRecordImpl() {
auto task = swift_task_getCurrent();

// a group must be in a task, so if we're not in a task...
// then, we certainly are not in a group either!
if (!task)
return false;

Optional<StatusRecordLockRecord> recordLockRecord;

// Acquire the status record lock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func printTaskLocal<V>(
// ==== ------------------------------------------------------------------------

@available(SwiftStdlib 5.5, *)
func synchronous_bind() async {
func synchronous_bind() {

func synchronous() {
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (1111)
Expand All @@ -45,14 +45,14 @@ func synchronous_bind() async {
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (1111)
}

await TL.$number.withValue(1111) {
TL.$number.withValue(1111) {
synchronous()
}
}

@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await synchronous_bind()
static func main() {
synchronous_bind()
}
}