Files
swift-mirror/test/Parse/identifiers.swift
Henrik G. Olsson cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00

63 lines
2.8 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated
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
}