File: consecutive_statements.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (72 lines) | stat: -rw-r--r-- 1,995 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
// RUN: %target-typecheck-verify-swift

func statement_starts() {
  var f : (Int) -> ()
  f = { (x : Int) -> () in }

  f(0)
  f (0)
  f // expected-warning{{variable is unused}}
  (0) // expected-warning {{integer literal is unused}}

  var a = [1,2,3]
  a[0] = 1
  a [0] = 1
  a // expected-warning{{variable is unused}}
  [0, 1, 2] // expected-warning {{expression of type '[Int]' is unused}}
}

// Within a function
func test(i: inout Int, j: inout Int) {
  // Okay
  let q : Int; i = j; j = i; _ = q

  if i != j { i = j }

  // Errors
  i = j j = i // expected-error{{consecutive statements}} {{8-8=;}}
  let r : Int i = j // expected-error{{consecutive statements}} {{14-14=;}}
  let s : Int let t : Int // expected-error{{consecutive statements}} {{14-14=;}}
  _ = r; _ = s; _ = t
}

struct X {
  // In a sequence of declarations.
  var a, b : Int func d() -> Int {} // expected-error{{consecutive declarations}} {{17-17=;}}

  var prop : Int { return 4
  } var other : Float // expected-error{{consecutive declarations}} {{4-4=;}}

  // Within property accessors
  subscript(i: Int) -> Float {
    get {
      var x = i x = i + x return Float(x) // expected-error{{consecutive statements}} {{16-16=;}} expected-error{{consecutive statements}} {{26-26=;}}
    }
    set {
      var x = i x = i + 1 // expected-error{{consecutive statements}} {{16-16=;}}
      _ = x
    }
  }
}

class C {
  // In a sequence of declarations.
  var a, b : Int func d() -> Int {} // expected-error{{consecutive declarations}} {{17-17=;}}
  init() {
    a = 0
    b = 0
  }
}

protocol P {
  func a() func b() // expected-error{{consecutive declarations}} {{11-11=;}}
}

enum Color {
  case Red case Blue // expected-error{{consecutive declarations}} {{11-11=;}}
  func a() {} func b() {} // expected-error{{consecutive declarations}} {{14-14=;}}
}

// At the top level
var i, j : Int i = j j = i // expected-error{{consecutive statements}} {{15-15=;}} expected-error{{consecutive statements}} {{21-21=;}}