mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
85 lines
3.7 KiB
Swift
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)
|
|
}
|