Files
swift-mirror/test/Macros/issue-80835.swift
Hamish Knight b36eb57dbd [Sema] Downgrade noasync diagnostic to warning for closure macro args
Downgrade to a warning until the next language mode. This is
necessary since we previously missed coercing macro arguments to
parameter types, resulting in cases where closure arguments weren't
being treated as `async` when they should have been.

rdar://149328745
2025-04-16 19:22:52 +01:00

85 lines
3.7 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
// RUN: %target-typecheck-verify-swift -swift-version 6 -load-plugin-library %t/%target-library-name(MacroDefinition) -verify-additional-prefix swift6-
// RUN: %target-typecheck-verify-swift -swift-version 7 -load-plugin-library %t/%target-library-name(MacroDefinition) -verify-additional-prefix swift7-
// REQUIRES: swift_swift_parser
// REQUIRES: swift7
// https://github.com/swiftlang/swift/issues/80835
@available(*, noasync)
func noasyncFn() {}
@_unavailableFromAsync
func unavailableFromAsyncFn() {} // expected-note {{'unavailableFromAsyncFn()' declared here}}
@freestanding(expression)
macro asyncMacro(_ fn: () async -> Void) = #externalMacro(module: "MacroDefinition", type: "GenericToVoidMacro")
@freestanding(declaration)
macro asyncMacroDecl(_ fn: () async -> Void) = #externalMacro(module: "MacroDefinition", type: "EmptyDeclarationMacro")
@attached(peer)
macro AsyncMacro(_ fn: () async -> Void) = #externalMacro(module: "MacroDefinition", type: "WrapperMacro")
func takesAsyncFn(_ fn: () async -> Void) {}
#asyncMacro {
defer {
noasyncFn()
// expected-swift7-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
}
noasyncFn()
// expected-swift7-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
unavailableFromAsyncFn()
// expected-swift7-error@-1 {{global function 'unavailableFromAsyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'unavailableFromAsyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
// This was always an error.
let _: () async -> Void = {
noasyncFn()
// expected-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
}
}
// This was always an error.
takesAsyncFn {
noasyncFn()
// expected-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
}
#asyncMacroDecl {
noasyncFn()
// expected-swift7-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
}
typealias Magic<T> = T
// expected-swift7-error@+2 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@+1 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
@AsyncMacro({ noasyncFn() })
func foo() {
#asyncMacro(({
noasyncFn()
// expected-swift7-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
}))
#asyncMacroDecl(({
noasyncFn()
// expected-swift7-error@-1 {{global function 'noasyncFn' is unavailable from asynchronous contexts}}
// expected-swift6-warning@-2 {{global function 'noasyncFn' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode}}
}))
// This was never treated as async.
#asyncMacro({
noasyncFn()
} as Magic)
}