Skip to content

Ensure that macro overloading via availability works #67748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/Macros/macro_availability_macos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,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'}}
}