File: identifiers.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 (62 lines) | stat: -rw-r--r-- 2,821 bytes parent folder | download | duplicates (2)
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
// RUN: %target-typecheck-verify-swift

func my_print<T>(_ t: T) {}

class 你好 {
  class שלום {
    class வணக்கம் {
      class Γειά {
        class func привет() {
          my_print("hello")
        }
      }
    }
  }
}

你好.שלום.வணக்கம்.Γειά.привет()

// Identifiers cannot start with combining chars.
_ = .́duh() // expected-error {{cannot find operator '.́' in scope}} // expected-error{{cannot find 'duh' in scope}}

// Combining characters can be used within identifiers.
func s̈pin̈al_tap̈() {}

// Private-use characters aren't valid in Swift source.
() // expected-error{{invalid character in source file}} {{1-4= }}

// Placeholders are recognized as identifiers but with error.
func <#some name#>() {} // expected-error {{editor placeholder in source file}}

// Keywords as identifiers
class switch {} // expected-error {{keyword 'switch' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{7-13=`switch`}}
struct Self {} // expected-error {{keyword 'Self' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{8-12=`Self`}}
protocol enum {} // expected-error {{keyword 'enum' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{10-14=`enum`}}
protocol test {
  associatedtype public // expected-error {{keyword 'public' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{18-24=`public`}}
}
func _(_ x: Int) {} // expected-error {{keyword '_' cannot be used as an identifier here}} // expected-note {{if this name is unavoidable, use backticks to escape it}} {{6-7=`_`}}

// SIL keywords are tokenized as normal identifiers in non-SIL mode.
_ = undef // expected-error {{cannot find 'undef' in scope}}
_ = sil // expected-error {{cannot find 'sil' in scope}}
_ = sil_stage // expected-error {{cannot find 'sil_stage' in scope}}
_ = sil_vtable // expected-error {{cannot find 'sil_vtable' in scope}}
_ = sil_global // expected-error {{cannot find 'sil_global' in scope}}
_ = sil_witness_table // expected-error {{cannot find 'sil_witness_table' in scope}}
_ = sil_default_witness_table // expected-error {{cannot find 'sil_default_witness_table' in scope}}
_ = sil_coverage_map // expected-error {{cannot find 'sil_coverage_map' in scope}}
_ = sil_scope // expected-error {{cannot find 'sil_scope' in scope}}

// https://github.com/apple/swift/issues/57542
// Make sure we do not parse the '_' on the newline as being part of the 'variable' identifier on the line before.

@propertyWrapper 
struct Wrapper {
  var wrappedValue = 0
}

func localScope() {
  @Wrapper var variable
  _ = 0
}