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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ParserASTGen > %t/astgen.ast.raw
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only > %t/cpp-parser.ast.raw
// Filter out any addresses in the dump, since they can differ.
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/cpp-parser.ast.raw > %t/cpp-parser.ast
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/astgen.ast.raw > %t/astgen.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan
// NB: Ridiculous formatting to test that we do not include leading trivia in locations.
func test1(x: Int, fn: (Int) -> Int) async throws -> Int {
let
xx = fn(42)
let y =
true
let arlit = [0]
let tuple = (0, 1)
let diclit = [0: 1, 2: 3]
return fn(x)
}
func test2(_ b: Swift.Bool) -> Int {
return if b { 0 } else { 1 }
}
func test3(_ b1: Bool, b2: Bool) -> Int {
let x = if b1 { 0 } else if b2 { 1 } else { 2 }
return x
}
func test4(_ b: [Bool]) -> Int {
if b.isEmpty { 0 } else {
1
}
}
func testEmptyDictionary() -> [Int: Int] {
return [:]
}
enum Ty {
case `self`
case `Self`
}
struct TestStruct {
func method(arg: Int, _ c: Int) {}
func test() {
_ = method(arg:_:)
_ = self.method(arg:_:).self
_ = Ty.`Self` == Ty.`self`
}
}
func testSequence(arg1: Int, arg2: () -> Int, arg3: Any) {
_ = arg1 + arg2()
_ = arg3 as? Int ?? 31 as Int
_ = false ? arg2() : Int(1)
_ = [() -> Int]()
_ = [@Sendable () -> Int]().count + [any Collection]().count
_ = arg3 is Double || !(arg3 is Int, 0).0
}
func asyncFunc(_ arg: String) async throws -> Int {
return 1
}
func testUnaryExprs() async throws {
let str = String()
let foo = try await asyncFunc(_borrow str)
let bar = copy foo
let baz = consume foo
}
func testRepeatEach<each T>(_ t: repeat each T) -> (repeat each T) {
return (repeat each t)
}
func acceptClosures(x: () -> Void) {}
func acceptClosures(x: () -> Void, y: () -> Int) {}
func acceptClosures(x: () -> Void, y: () -> Int, _ z: () -> Void) {}
func testTrailingClsure() {
acceptClosures {}
acceptClosures() {}
acceptClosures(x: {}) { 42 }
acceptClosures(x: {}) { 12 } _: {}
acceptClosures {} y: { 42 }
acceptClosures(x: {}, y: { 12 }) {}
}
func testStringLiteral(arg: Int) {
_ = "test"
_ = "foo\(arg)bar"
_ = "\(arg)"
_ = """
foo
bar\
baz
"""
_ = """
foo\(arg)
\(arg)bar
"""
_ = "\n\r\u{1234}"
_ = """
foo
\(
("bar", """
\tbaz\u{0d}
"""
)
)
baz
"""
}
|