Skip to content
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

Calling noasync function inside a defer #73614

Closed
0xTim opened this issue May 14, 2024 · 0 comments · Fixed by #73841
Closed

Calling noasync function inside a defer #73614

0xTim opened this issue May 14, 2024 · 0 comments · Fixed by #73841
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@0xTim
Copy link

0xTim commented May 14, 2024

Description

When annotating a function as noasync, the compiler should produce a warning when calling that function from an async context - such as an async function. When calling a noasync function from a defer block inside an async function, the warning is not produced which can lead to unexpected behaviour.

Reproduction

@available(*, noasync, message: "Don't call async contexts")
func somethingSync() {
  print("Sync")
}

func asyncFunc() async {
  somethingSync() // This produces a warning

  defer {
    somethingSync() // This does not produce a warning but should
  }

  print("Async")
}

Expected behavior

The compiler should produce 2 warnings, for each call of somethingSync() inside asyncFunc. It currently only produces a warning for the call outside the defer block

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@0xTim 0xTim added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 14, 2024
@ktoso ktoso changed the title Calling noasync function inside a `defer Calling noasync function inside a defer May 15, 2024
@ktoso ktoso added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels May 15, 2024
jamieQ added a commit to jamieQ/swift that referenced this issue May 23, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
jamieQ added a commit to jamieQ/swift that referenced this issue May 24, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
jamieQ added a commit to jamieQ/swift that referenced this issue May 24, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
jamieQ added a commit to jamieQ/swift that referenced this issue May 24, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
jamieQ added a commit to jamieQ/swift that referenced this issue May 25, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
jamieQ added a commit to jamieQ/swift that referenced this issue May 27, 2024
updates noasync diagnostics in TypeCheckAvailability.cpp to diagnose
defer bodies as if they had the same `isAsyncContext()` value as their
nearest non-defer parent scope.

resolves: apple#73614
(cherry picked from commit e68c36b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants