File: inline_array.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (107 lines) | stat: -rw-r--r-- 4,171 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
// RUN: %target-typecheck-verify-swift -disable-availability-checking

let _: [3 of Int]
let _ = [3 of Int](repeating: 0)
let _ = [3 of [3 of Int]](repeating: [1, 2, 3])

let _ = [[3 of Int] of Int]() // expected-error {{cannot pass type '[3 of Int]' as a value for generic value 'count'}}

do {
  let _: [3 of
  // expected-error@-1 {{expected type}}
}

do {
  let _: [3 of Int // expected-note {{to match this opening '['}}
} // expected-error {{expected ']' in inline array type}}

// We don't currently allow multi-line.
func testMultiline(_ of: Int) {
  let _ = [ // expected-error {{cannot call value of non-function type '[Int]'}}
    3 // expected-error {{expected ',' separator}}
    of
    Int
  ](repeating: 0)

  let _ = [3
    of
    Int
  ](repeating: 0)
  // expected-error@-4 {{expected ',' separator}}
  // expected-error@-5 {{cannot call value of non-function type '[Int]'}}

  let _ = [3
           of Int](repeating: 0)
  // expected-error@-2 {{cannot call value of non-function type '[Int]'}}
  // expected-error@-3 {{expected ',' separator}}

  // This is okay.
  let _ = [3 of
             Int](repeating: 0)

  // So's this
  let _ = [
    3 of Int
  ](repeating: 0)
}

protocol P {}
protocol Q {}

struct S<T> {}

let _ = S<[3 of Int]>()
let _ = S<[[3 of Int]]>()

// Make sure we can recover for different type productions as the LHS.
let _ = S<[[Int of 3]]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[@escaping () -> Int of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{'@escaping' may only be used in function parameter position}}
let _ = S<[Int.Type of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[sending P & Q of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{'sending' may only be used on parameters and results}}
let _ = S<[some P & Q -> Int of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{single argument function types require parentheses}}
// expected-error@-3 {{'some' types are only permitted in properties, subscripts, and functions}}
let _ = S<[~P of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{type 'P' cannot be suppressed}}
let _ = S<[(Int, String) of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[[3 of Int] of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[[Int] of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[Array<Int> of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
let _ = S<[_ of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{could not infer type for placeholder}}
let _ = S<[_? of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{could not infer type for placeholder}}
let _ = S<[_?of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-error@-2 {{could not infer type for placeholder}}
let _ = S<[_! of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-warning@-2 {{using '!' here is deprecated; this is an error in the Swift 5 language mode}}
// expected-note@-3 {{use '?' instead}}
// expected-error@-4 {{could not infer type for placeholder}}
let _ = S<[_!of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}
// expected-warning@-2 {{using '!' here is deprecated; this is an error in the Swift 5 language mode}}
// expected-note@-3 {{use '?' instead}}
// expected-error@-4 {{could not infer type for placeholder}}
let _ = S<[Int?of 3]>()
// expected-error@-1 {{element count must precede inline array element type}}

func testEllipsis(_ of: Int) {
  // Make sure this isn't parsed as '<variadic-type> of <missing type>'
  let _ = [of...of]
}