I ran into a case where compiler-generated code that calls availability-gated code compiles and runs successfully:
struct Test {
@MakeIndirectCall
static func greet(name: String) -> String {
return "Hello, \(name)!"
}
/* Expanded Macro
static func greet_indirect(name: String) -> String {
return greet(name: name)
}
*/
@available(macOS 99, iOS 99, *)
@MakeIndirectCall
static func triple(x: Int) -> Int {
return 3 * x
}
/* Expanded Macro
static func triple_indirect(x: Int) -> Int {
return triple(x: x)
}
*/
}
@main
struct Client {
static func main() {
print(Test.greet(name: "World")) // β
OK
print(Test.greet_indirect(name: "World")) // β
OK
// print(Test.triple(x: 5)) // β 'triple(x:)' is only available in macOS 99 or newer
print(Test.triple_indirect(x: 5)) // β οΈ SHOULD ERROR (?) , BUT DOESN'T
}
}
Hello, World!
Hello, World!
15
However, if I manually inline the macro expansion in Xcode I get an availability error:
static func triple_indirect(x: Int) -> Int {
return triple(x: x) // β 'triple(x:)' is only available in macOS 99 or newer
}
Is this expected or a compiler bug?