Files
swift-mirror/test/Macros/macro_self.swift
Rintaro Ishizaki b119407966 [Parse] Change whitespace rule between attribute name and '(' in Swift 6
In Swift 6 and later, whitespace is no longer permitted between an
attribute name and the opening parenthesis. Update the parser so that
in Swift 6+, a `(` without preceding whitespace is always treated as
the start of the argument list, while a '(' with preceding whitespace is
considered the start of the argument list _only when_ it is unambiguous.

This change makes the following closure be parsed correctly:

  { @MainActor (arg: Int) in ... }

rdar://147785544
2025-09-09 16:44:29 -07:00

30 lines
692 B
Swift

// RUN: %target-swift-frontend -parse %s -verify
@freestanding(expression)
macro self() = #externalMacro(module: "MacroDefinition", type: "InvalidMacro")
// expected-error@-1 {{expected declaration}}
func sync() {}
@freestanding(expression)
macro Self() = #externalMacro(module: "MacroDefinition", type: "InvalidMacro")
// expected-error@-1 {{expected declaration}}
func testSelfAsFreestandingMacro() {
_ = #self
}
func testCapitalSelfAsFreestandingMacro() {
_ = #Self
}
func testSelfAsAttachedMacro() {
@self // expected-error {{expected expression}}
struct Foo {}
}
func testCapitalSelfAsAttachedMacro() {
@Self // expected-error {{expected expression}}
struct Foo {}
}