mirror of
https://github.com/apple/swift.git
synced 2026-10-06 12:37:28 +02:00
For peer, conformance, and extension macros, the macro expansion buffer is logically a sibling of the attached declaration rather than nested inside it. Looking up the buffer's parent availability scope using the attached declaration's source location therefore lands inside the attached declaration's own scope and the expansion silently inherits its @available constraints. Compute the parent scope from the buffer's logical declaration context instead so that sibling expansions are checked at the enclosing context's availability, matching the behavior of equivalent code written by hand. Resolves https://github.com/swiftlang/swift/issues/89936 and rdar://179585474.
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
// 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'}}
|
|
}
|