swiftlang / swiftlang/swift-syntax

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

Open
#2,256 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

### Description

If I attempt to label closure arguments during macro expansion:

```swift
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:

```swift
@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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.