- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathissue-80835.swift
84 lines (66 loc) · 3.73 KB
/
issue-80835.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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}}
}
typealiasMagic<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()
}asMagic)
}