Skip to content

makeUniqueName() produces tokens that cannot be used as closure arguments #2256

Open
@grynspan

Description

@grynspan

Description

If I attempt to label closure arguments during macro expansion:

let arg0 = context.makeUniqueName("")
return """
{ \(arg0) in
  ...
}
"""

The compiler complains:

🛑 Inferred projection type 'Int' is not a property wrapper
🛑 Inferred projection type '() -> Int' is not a property wrapper

This means I can't reliably produce closure argument names, which is problematic if my macro expansion generates a closure and the macro is being used inside another closure:

@Test func foo() {
  let x = [2, 4, 6]
  x.forEach {
    #expect($0 % 2 == 0) // 🛑 Anonymous closure arguments cannot be used inside
                         // a closure that has explicit arguments; did you mean '$0'?
  }
}

Steps to Reproduce

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions