-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathmacro_availability_macos.swift
36 lines (28 loc) · 1.34 KB
/
macro_availability_macos.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
// REQUIRES: swift_swift_parser, asserts
// REQUIRES: OS=macosx
// RUN: %target-typecheck-verify-swift -swift-version 5 -module-name MacrosTest -target %target-cpu-apple-macos50
@freestanding(expression)
macro overloadedOnAvailability(_: Any) -> Int = #externalMacro(module: "MacroLibrary", type: "MyOldMacro")
//expected-warning@-1{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
// expected-note@-2 2{{'overloadedOnAvailability' declared here}}
@available(macOS 60, *)
@freestanding(expression)
macro overloadedOnAvailability(_: Int) -> Double = #externalMacro(module: "MacroLibrary", type: "MyNewMacro")
//expected-warning@-1{{external macro implementation type 'MacroLibrary.MyNewMacro'}}
// expected-note@-2{{'overloadedOnAvailability' declared here}}
func mutateInt(_: inout Int) { }
func mutateDouble(_: inout Double) { }
func testAvailabilityOld() {
var a = #overloadedOnAvailability(1)
mutateInt(&a)
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
}
@available(macOS 60, *)
func testAvailabilitNew(a: Any) {
var a = #overloadedOnAvailability(1)
mutateDouble(&a)
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyNewMa}}
var b = #overloadedOnAvailability(a)
mutateInt(&b)
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
}