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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_VOID_1 | %FileCheck %s -check-prefix=RETURN_VOID_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_INT_1 | %FileCheck %s -check-prefix=RETURN_INT_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_INT_2 | %FileCheck %s -check-prefix=RETURN_INT_2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TRY_RETURN_INT | %FileCheck %s -check-prefix=RETURN_INT_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TRY_RETURN_VOID | %FileCheck %s -check-prefix=RETURN_VOID_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR1 | %FileCheck %s -check-prefix=RETURN_TR1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR2 | %FileCheck %s -check-prefix=RETURN_TR2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR3 | %FileCheck %s -check-prefix=RETURN_TR3
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR1_METHOD | %FileCheck %s -check-prefix=RETURN_TR1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR2_METHOD | %FileCheck %s -check-prefix=RETURN_TR2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR3_METHOD | %FileCheck %s -check-prefix=RETURN_TR3
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR1_STATICMETHOD | %FileCheck %s -check-prefix=RETURN_TR1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR2_STATICMETHOD | %FileCheck %s -check-prefix=RETURN_TR2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR3_STATICMETHOD | %FileCheck %s -check-prefix=RETURN_TR3
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR1_CLOSURE | %FileCheck %s -check-prefix=RETURN_TR1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR2_CLOSURE | %FileCheck %s -check-prefix=RETURN_TR2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_TR3_CLOSURE | %FileCheck %s -check-prefix=RETURN_TR3
struct FooStruct {
var instanceVar : Int
}
class InternalGen {
func InternalIntGen() -> Int { return 0 }
func InternalIntOpGen() -> Int? {return 0 }
func InternalStringGen() -> String { return "" }
func InternalStringOpGen() -> String? {return ""}
func InternalIntTaker(_ i1 : Int, i2 : Int) {}
func InternalStringTaker(_ s1: String, s2 : String) {}
}
class Gen {
var IG = InternalGen()
func IntGen() -> Int { return 0 }
func IntOpGen() -> Int? {return 0 }
func StringGen() -> String { return "" }
func StringOpGen() -> String? {return ""}
func IntTaker(_ i1 : Int, i2 : Int) {}
func StringTaker(_ s1: String, s2 : String) {}
}
func testReturnVoid1() {
return #^RETURN_VOID_1^#
// It is questionable if we should provide any results in a function returning
// Void. But, the compiler allows us to put an expression of type Void here.
// A similar construct is also allowed in C, and might be used to cause a
// compiler error if the type of that expression changes to non-void.
// RETURN_VOID_1-DAG: Decl[Struct]/CurrModule: FooStruct[#FooStruct#]{{; name=.+$}}
}
func testReturnInt1() {
return #^RETURN_INT_1^#
// RETURN_INT_1-DAG: Decl[Struct]/CurrModule: FooStruct[#FooStruct#]{{; name=.+$}}
}
func testReturnInt2(_ fooObject: FooStruct) {
return fooObject.#^RETURN_INT_2^#
// RETURN_INT_2: Begin completions, 2 items
// RETURN_INT_2-DAG: Keyword[self]/CurrNominal: self[#FooStruct#]; name=self
// RETURN_INT_2-DAG: Decl[InstanceVar]/CurrNominal: instanceVar[#Int#]{{; name=.+$}}
}
func testMisplacedTry() throws -> Int {
try return #^TRY_RETURN_INT^#
}
func testMisplacedTryVoid() throws {
try return #^TRY_RETURN_VOID^#
}
func testTR1() -> Int? {
var i : Int
var oi : Int?
var fs : FooStruct
return #^RETURN_TR1^#
// RETURN_TR1-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: oi[#Int?#]{{; name=.+$}}
// RETURN_TR1-DAG: Decl[FreeFunction]/CurrModule/TypeRelation[Convertible]: testTR1()[#Int?#]{{; name=.+$}}
// RETURN_TR1-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: i[#Int#]{{; name=.+$}}
// RETURN_TR1-DAG: Decl[FreeFunction]/CurrModule/TypeRelation[Invalid]: testReturnInt1()[#Void#]{{; name=.+$}}
// RETURN_TR1-DAG: Decl[LocalVar]/Local: fs[#FooStruct#]{{; name=.+$}}
}
func testTR2(_ g : Gen) -> Int? {
return g.#^RETURN_TR2^#
}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: IntGen()[#Int#]{{; name=.+$}}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: IntOpGen()[#Int?#]{{; name=.+$}}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal: StringGen()[#String#]{{; name=.+$}}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal: StringOpGen()[#String?#]{{; name=.+$}}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: IntTaker({#(i1): Int#}, {#i2: Int#})[#Void#]{{; name=.+$}}
// RETURN_TR2-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: StringTaker({#(s1): String#}, {#s2: String#})[#Void#]{{; name=.+$}}
func testTR3(_ g : Gen) -> Int? {
return g.IG.#^RETURN_TR3^#
}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: InternalIntGen()[#Int#]{{; name=.+$}}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: InternalIntOpGen()[#Int?#]{{; name=.+$}}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal: InternalStringGen()[#String#]{{; name=.+$}}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal: InternalStringOpGen()[#String?#]{{; name=.+$}}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: InternalIntTaker({#(i1): Int#}, {#i2: Int#})[#Void#]{{; name=.+$}}
// RETURN_TR3-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: InternalStringTaker({#(s1): String#}, {#s2: String#})[#Void#]{{; name=.+$}}
struct TestStruct {
func testTR1_method() -> Int? {
var i : Int
var oi : Int?
var fs : FooStruct
return #^RETURN_TR1_METHOD^#
}
func testTR2_method(_ g : Gen) -> Int? {
return g.#^RETURN_TR2_METHOD^#
}
func testTR3_method(_ g : Gen) -> Int? {
return g.IG.#^RETURN_TR3_METHOD^#
}
static func testTR1_static() -> Int? {
var i : Int
var oi : Int?
var fs : FooStruct
return #^RETURN_TR1_STATICMETHOD^#
}
static func testTR2_static(_ g : Gen) -> Int? {
return g.#^RETURN_TR2_STATICMETHOD^#
}
static func testTR3_static(_ g : Gen) -> Int? {
return g.IG.#^RETURN_TR3_STATICMETHOD^#
}
}
func testClosures(_ g: Gen) {
var i : Int
var oi : Int?
var fs : FooStruct
_ = { () -> Int? in
return #^RETURN_TR1_CLOSURE^#
}
_ = { () -> Int? in
return g.#^RETURN_TR2_CLOSURE^#
}
_ = { () -> Int? in
return g.IG.#^RETURN_TR3_CLOSURE^#
}
}
|