mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Raw identifiers are backtick-delimited identifiers that can contain any non-identifier character other than the backtick itself, CR, LF, or other non-printable ASCII code units, and which are also not composed entirely of operator characters.
53 lines
1.4 KiB
Swift
53 lines
1.4 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// 1. functional test:
|
|
|
|
// RUN: %target-build-swift %s -emit-executable -o %t/a.out
|
|
// RUN: %target-codesign %t/a.out
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
|
|
// 2. check if the generated IR looks like what we expect:
|
|
|
|
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s -check-prefix=CHECK-IR
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
func tupleCast<T, U>(_ t: (notRaw1: T, notRaw2: U)) -> Bool {
|
|
return t is (notRaw1: Int, notRaw2: String)
|
|
// CHECK-IR: @".str.16.notRaw1 notRaw2 " = private unnamed_addr constant [17 x i8] c"notRaw1 notRaw2 \00"
|
|
}
|
|
|
|
func tupleCast<T, U>(_ t: (`raw 1`: T, `raw 2`: U)) -> Bool {
|
|
return t is (`raw 1`: Int, `raw 2`: String)
|
|
// CHECK-IR: @".str.18.`raw\C2\A01` `raw\C2\A02` " = private unnamed_addr constant [19 x i8] c"`raw\C2\A01` `raw\C2\A02` \00"
|
|
}
|
|
|
|
func test() {
|
|
var failed = false
|
|
if !tupleCast((notRaw1: 10, notRaw2: "hello")) {
|
|
print("failed: cast should have passed")
|
|
failed = true
|
|
}
|
|
if tupleCast((notRaw1: 10, notRaw2: 11)) {
|
|
print("failed: cast should not have passed")
|
|
failed = true
|
|
}
|
|
|
|
if !tupleCast((`raw 1`: 10, `raw 2`: "hello")) {
|
|
print("failed: cast should have passed")
|
|
failed = true
|
|
}
|
|
if tupleCast((`raw 1`: 10, `raw 2`: 11)) {
|
|
print("failed: cast should not have passed")
|
|
failed = true
|
|
}
|
|
|
|
if !failed {
|
|
print("passed")
|
|
}
|
|
}
|
|
|
|
test()
|
|
// CHECK: passed
|
|
// CHECK-NOT: failed
|