File: trailing-comma.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (137 lines) | stat: -rw-r--r-- 3,335 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// RUN: %target-swift-frontend -parse -verify %s

// Array Literal

let values = [1,2,3,]

let values: [Int,] = [] // expected-note {{to match this opening '['}} expected-error {{expected ']' in array type}} expected-error {{expected pattern}} 

// Tuple and Tuple Pattern

let _ = (a: 1, b: 2, c: 3,)

let (_, _,) = (0,1,)

// Arguments and Parameters

func foo(a: Int = 0, b: Int = 0, c: Int = 0,) -> Int {
    return a + b + c
}

foo(a: 1, b: 2, c: 3,)

// Subscript

foo[1, 2,]

// KeyPath Subscript

\Foo.bar[0,1,]

// Generic Parameters

struct S<T1, T2,> { }

func foo<T1, T2,>() { }

protocol P<T1, T2> {
    associatedtype T1
    associatedtype T2
}

// Closure Capture List

let _ = { [obj1, obj2,] in }

// Attributes

@Foo(a, b, c,) struct S { }

f(_: @foo(1, 2,) Int)

// Macro Expansions

#foo(1, 2,)

struct S {
    #foo(1, 2,)
}

// String Literal Interpolation

"\(1,)"

// Availability Spec List

if #unavailable(iOS 15, watchOS 9,) { }

if #available(iOS 15,) { }  // expected-error {{expected platform name}}

// Built-in Attributes

@attached(extension, conformances: OptionSet,)  // expected-error {{unexpected ',' separator}}
macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")

@inline(never,) // expected-error {{expected declaration}} expected-error {{expected ')' in 'inline' attribute}} 
func foo() { }

@available(iOS 15,) // expected-error {{expected platform name}} expected-error {{expected declaration}} 
func foo() { }

@backDeployed(before: SwiftStdlib 6.0,) // expected-error {{unexpected ',' separator}}
func foo() { }

struct Foo {
    
  var x: Int
  var y: Int
  
  var value: (Int, Int) {
    @storageRestrictions(initializes: x, y,)  // expected-error {{expected property name in @storageRestrictions list}}
    init(initialValue) {
      self.x = initialValue.0
      self.y = initialValue.1
    }
    get { (x, y) }
  }

}

func f(in: @differentiable(reverse,) (Int) -> Int) { } // expected-warning {{@differentiable' has been renamed to '@differentiable(reverse)' and will be removed in the next release}} expected-error {{unexpected ',' separator}} expected-error {{expected ',' separator}} expected-error {{unnamed parameters must be written with the empty name '_'}} 

@derivative(of: Self.other,) // expected-error {{unexpected ',' separator}}
func foo() {}

@transpose(of: S.instanceMethod,) // expected-error {{unexpected ',' separator}}
func transposeInstanceMethodWrtSelf(_ other: S, t: S) -> S {
    other + t
}

// The following cases are only supported with the 'TrailingComma' experimental feature flag enabled
 
// Switch Case Pattern List

switch number {
    case 1, 2,: // expected-error {{expected pattern}} 
        break
    default:
        break
}

// Generic Where Clause List

struct S<T1, T2, T3,> where T1: P1, T2: P2, { } // expected-error {{expected type}} 

// Inheritance Clause List

struct S: P1, P2, P3, { } // expected-error {{expected type}} 

struct S<T>: P1, P2, P3, where T: Equatable { } // expected-error {{expected type}} expected-error {{expected '{' in struct}} 

// Condition List

if true, { } // expected-error {{expected '{' after 'if' condition}} 

guard true, else { } // expected-error {{expected expression in conditional}} 

while true, { } // expected-error {{expected '{' after 'while' condition}}