Open FlickerSoul opened 7 months ago
In addition, if the macro is applied in the following way
enum Test {
@bug({ (input: Int) -> Int in input * 10 })
case test
}
Xcode prompts that input
in input * 10
cannot be found.
If the bug
macro were not generic parametrized, anonymous arguments will work, for example { $0 * 10 }
. But if the function arguments are generic, compilers cannot infer the type of the arguments, thus leading us annotate the types explicitly. And in this situation, xcode informs the problem above.
And again, if the closure is extracted, the program compiles
let lambda = { (input: Int) -> Int in input * 10 }
enum Test {
@bug(lambda)
case test
}
Description
A macro can be generic. The official template
stringify
uses it.It's natural to create a macro that accepts a closure, for example,
The
bug
extension macro can be applied to a structHowever, the compiler fails to compile the
Test
struct above.Reproduction
Create a macro package from xcode template named
Bug
. This can be reproduced using the 5.9.1 release toolchain or the latest snapshot (2023-12-07) toolchain.In the
BugMacro.swift
under theBugMacros
module,In
Bug.swift
under theBug
module,In
main.swift
under theBugClient
module,Stack dump
Expected behavior
The program should compile?
If the closure is extract out as the following, the program compiles
Environment
Additional information
No response