Skip to content

[6.1] Compilation fails when body macro is applied to function with closure capture list #80050

@davdroman

Description

@davdroman

Description

When applying a body macro to a function, compilation fails if the function contains a closure with a capture list.

Removing either the macro or the capture resolves the issue.

Reproduction

class Demo {
	@NoOpBodyMacro // this macro does nothing but return the body as-is, so it's fundamentally a no-op
	func demo() {
		let closure = { [weak self] in // 🛑 error: Type of expression is ambiguous without a type annotation
			// no-op
		}
	}
}

Build BodyMacroErrorDemo_2025-03-17T00-48-24.txt

Expected behavior

The code above compiles.

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.109.103 clang-1700.0.13.2)
Target: arm64-apple-macosx15.0
Xcode 16.3.0 beta 2

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions