-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathraw_identifier_tuple_elements.swift
52 lines (41 loc) · 1.4 KB
/
raw_identifier_tuple_elements.swift
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
// 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