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

73 lines
1.8 KiB
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-feature DefaultIsolationPerFile
// REQUIRES: swift_feature_DefaultIsolationPerFile
// REQUIRES: concurrency
using @MainActor
// expected-note@-1 {{default isolation was previously declared here}}
using nonisolated
// expected-error@-1 {{invalid redeclaration of file-level default actor isolation}}
using @Test // expected-error {{default isolation can only be set to '@MainActor' or 'nonisolated'}}
using test // expected-error {{default isolation can only be set to '@MainActor' or 'nonisolated'}}
do {
using // expected-warning {{expression of type 'Int' is unused}}
@MainActor
// expected-error@+1 {{expected declaration}}
}
do {
using // expected-warning {{expression of type 'Int' is unused}}
nonisolated // expected-error {{cannot find 'nonisolated' in scope}}
}
do {
func
using (x: Int) {}
using(x: 42)
}
do {
func
using
(x: Int) {}
using(x: 42)
}
let
using = 42
let (x: Int, using: String) = (x: 42, using: "")
do {
using @MainActor // expected-error {{declaration is only valid at file scope}}
}
func test() {
using @MainActor // expected-error {{declaration is only valid at file scope}}
}
struct S {
var x: Int {
using @MainActor // expected-error {{declaration is only valid at file scope}}
}
using @MainActor func test() {}
// expected-error@-1 {{declaration is only valid at file scope}}
// expected-error@-2 {{consecutive declarations on a line must be separated by ';'}}
using nonisolated subscript(a: Int) -> Bool { false }
// expected-error@-1 {{declaration is only valid at file scope}}
// expected-error@-2 {{consecutive declarations on a line must be separated by ';'}}
}
do {
@objc using @MainActor
// expected-error@-1 {{declaration is only valid at file scope}}
}