Files
swift-mirror/test/Parse/attribute_spacing_swift6.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

48 lines
1.5 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 6
@ MainActor // expected-error {{extraneous whitespace between '@' and attribute name}}
class Foo {
func funcWithEscapingClosure(_ x: @ escaping () -> Int) {} // expected-error {{extraneous whitespace between '@' and attribute name}}
}
@available (*, deprecated) // expected-error {{extraneous whitespace between attribute name and '('}}
func deprecated() {}
@propertyWrapper
struct MyPropertyWrapper {
var wrappedValue: Int = 1
init(param: Int) {}
}
struct PropertyWrapperTest {
@MyPropertyWrapper (param: 2) // expected-error {{extraneous whitespace between attribute name and '('}}
var x: Int
@MyPropertyWrapper
(param: 2) // expected-error {{expected 'var' keyword in property declaration}} expected-error {{property declaration does not bind any variables}} expected-error {{expected pattern}}
var y: Int
}
let closure1 = { @MainActor (a, b) in
// expected-error@-1 {{cannot infer type of closure parameter 'a' without a type annotation}}
// expected-error@-2 {{cannot infer type of closure parameter 'b' without a type annotation}}
}
let closure2 = { @MainActor
(a: Int, b: Int) in
let _: Int = a
}
// expected-error@+1 {{extraneous whitespace between '@' and attribute name}}
@
MainActor
func mainActorFunc() {}
@inline // expected-error {{expected '(' in 'inline' attribute}}
(never) func neverInline() {} // expected-error {{expected declaration}}
@objc
(whatever) func whateverObjC() {} // expected-error {{expected declaration}}