Skip to content

Commit 363e437

Browse files
committed
Ensure that macro overloading via availability works
This was already fixed by a previous change (#67698), but this introduces a test case to ensure that we don't regress rdar://113047811.
1 parent 0e80b4e commit 363e437

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// REQUIRES: swift_swift_parser, asserts
2+
// REQUIRES: OS=macosx
3+
4+
// RUN: %target-typecheck-verify-swift -swift-version 5 -module-name MacrosTest -target %target-cpu-apple-macos50
5+
6+
@freestanding(expression)
7+
macro overloadedOnAvailability(_: Any) -> Int = #externalMacro(module: "MacroLibrary", type: "MyOldMacro")
8+
//expected-warning@-1{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
9+
// expected-note@-2 2{{'overloadedOnAvailability' declared here}}
10+
11+
@available(macOS 60, *)
12+
@freestanding(expression)
13+
macro overloadedOnAvailability(_: Int) -> Double = #externalMacro(module: "MacroLibrary", type: "MyNewMacro")
14+
//expected-warning@-1{{external macro implementation type 'MacroLibrary.MyNewMacro'}}
15+
// expected-note@-2{{'overloadedOnAvailability' declared here}}
16+
17+
18+
func mutateInt(_: inout Int) { }
19+
func mutateDouble(_: inout Double) { }
20+
21+
func testAvailabilityOld() {
22+
var a = #overloadedOnAvailability(1)
23+
mutateInt(&a)
24+
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
25+
}
26+
27+
@available(macOS 60, *)
28+
func testAvailabilitNew(a: Any) {
29+
var a = #overloadedOnAvailability(1)
30+
mutateDouble(&a)
31+
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyNewMa}}
32+
33+
var b = #overloadedOnAvailability(a)
34+
mutateInt(&b)
35+
// expected-error@-2{{external macro implementation type 'MacroLibrary.MyOldMacro'}}
36+
}

0 commit comments

Comments
 (0)