File: unqualified_name.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 (95 lines) | stat: -rw-r--r-- 4,233 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
// RUN: %target-typecheck-verify-swift -swift-version 4

func f0(_ x: Int, y: Int, z: Int) { }
func f1(_ x: Int, while: Int) { }
func f2(_ x: Int, `let` _: Int) { }
func f3(_ x: Int, `var` _: Int) { }
func f4(_ x: Int, _ y: Int, z: Int) { }

func test01() {
  _ = f0(_:y:z:)
  _ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{10-10=_}}
  _ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{12-13=}}{{18-19=}}
  _ = f2(_:`let`:) // expected-warning {{keyword 'let' does not need to be escaped in argument list}} {{12-13=}} {{16-17=}}
  _ = f3(_:`var`:) // expected-warning {{keyword 'var' does not need to be escaped in argument list}} {{12-13=}} {{16-17=}}
  _ = f4(_::z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
}

struct S0 {
  func f0(_ x: Int, y: Int, z: Int) { }
  func f1(_ x: Int, while: Int) { }
  func f2(_ x: Int, `let` _: Int) { }
  func f3(_ x: Int, `var` _: Int) { }

  func testS0() {
    _ = f0(_:y:z:)
    _ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
    _ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{14-15=}}{{20-21=}}
    _ = f2(_:`let`:) // expected-warning {{keyword 'let' does not need to be escaped in argument list}} {{14-15=}} {{18-19=}}
    _ = f3(_:`var`:) // expected-warning {{keyword 'var' does not need to be escaped in argument list}} {{14-15=}} {{18-19=}}
    
    _ = self.f0(_:y:z:)
    _ = self.f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{17-17=_}}
    _ = self.f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{19-20=}}{{25-26=}}
    _ = self.f2(_:`let`:) // expected-warning {{keyword 'let' does not need to be escaped in argument list}}{{19-20=}}{{23-24=}}
    _ = self.f3(_:`var`:) // expected-warning {{keyword 'var' does not need to be escaped in argument list}}{{19-20=}}{{23-24=}}

    _ = f3(_:y:z:) // expected-error{{static member 'f3(_:y:z:)' cannot be used on instance of type 'S0'}}{{9-9=S0.}}
  }

  static func testStaticS0() {
    _ = f0(_:y:z:)
    _ = f3(_:y:z:)
  }

  static func f3(_ x: Int, y: Int, z: Int) -> S0 { return S0() }
}

// Determine context from type.
let s0_static: S0 = .f3(_:y:z:)(0, y: 0, z: 0)

class C0 {
  init(x: Int, y: Int, z: Int) { }

  convenience init(all: Int) {
    self.init(x:y:z:)(all, all, all)
  }

  func f0(_ x: Int, y: Int, z: Int) { }
  func f1(_ x: Int, while: Int) { }
  func f2(_ x: Int, `let` _: Int) { }
  func f3(_ x: Int, `var` _: Int) { }
}

class C1 : C0 {
  init(all: Int) {
    super.init(x:y:z:)(all, all, all)
  }

  func testC0() {
    _ = f0(_:y:z:)
    _ = f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{12-12=_}}
    _ = f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{14-15=}}{{20-21=}}
    _ = f2(_:`let`:) // expected-warning {{keyword 'let' does not need to be escaped in argument list}} {{14-15=}} {{18-19=}}
    _ = f3(_:`var`:) // expected-warning {{keyword 'var' does not need to be escaped in argument list}} {{14-15=}} {{18-19=}}
    
    _ = super.f0(_:y:z:)
    _ = super.f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{18-18=_}}
    _ = super.f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{20-21=}}{{26-27=}}
    _ = self.f2(_:`let`:) // expected-warning {{keyword 'let' does not need to be escaped in argument list}} {{19-20=}} {{23-24=}}
    _ = self.f3(_:`var`:) // expected-warning {{keyword 'var' does not need to be escaped in argument list}} {{19-20=}} {{23-24=}}
    
  }
}

struct S1 {
  init(x: Int) {} // expected-note {{'init(x:)' declared here}}

  func testS1() {
    _ = S1.init(x:)(1)
    _ = S1.init(`x`: 1)  // expected-warning {{keyword 'x' does not need to be escaped in argument list}} {{17-18=}} {{19-20=}}

    // Test for unknown token.
    _ = S1.init(x: 0xG) // expected-error {{'G' is not a valid hexadecimal digit (0-9, A-F) in integer literal}} expected-error {{missing argument for parameter 'x' in call}}
  }
}