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
|
// RUN: %batch-code-completion -enable-experimental-feature ImplicitLastExprResults -debug-forbid-typecheck-prefix FORBIDDEN
// Experimental feature requires asserts
// REQUIRES: asserts
enum E {
case e
case f(Int)
}
struct NO {
// Triggering interface type computation of this will cause an assert to fire,
// ensuring we don't attempt to type-check any references to it.
static var TYPECHECK = FORBIDDEN
}
func test1() -> E {
if .random() {
();
.#^DOT1?check=DOT^#
} else {
.e
}
}
func test2() -> E {
switch Bool.random() {
case true:
.e
case false:
();
.#^DOT2?check=DOT^#
}
}
func test3() throws -> E {
switch Bool.random() {
case true:
NO.TYPECHECK
throw NO.TYPECHECK
case false:
();
.#^DOT3?check=DOT^#
}
}
struct S {
var e: E
}
func test4() throws -> E {
let x = switch Bool.random() {
case true:
NO.TYPECHECK
throw NO.TYPECHECK
case false:
let s = S(e: .e)
s.#^SDOT1?check=SDOT^#
}
return x
}
func test5() -> E {
();
.#^DOT4?check=DOT^#
}
func test6() -> E {
let fn: () -> E = {
();
.#^DOT5?check=DOT^#
}
return fn()
}
func test7() throws -> E {
print("hello")
switch Bool.random() {
case true:
NO.TYPECHECK
throw NO.TYPECHECK
case false:
();
.#^DOT7?check=DOT^#
}
}
// SDOT: Begin completions, 2 items
// SDOT-DAG: Keyword[self]/CurrNominal: self[#S#]; name=self
// SDOT-DAG: Decl[InstanceVar]/CurrNominal: e[#E#]; name=e
// DOT: Begin completions, 2 items
// DOT-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: e[#E#]; name=e
// DOT-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: f({#Int#})[#E#]; name=f()
struct TestImplicitLastExprMember {
func void() -> Void {}
func str() -> String { return "" }
func int() -> Int { return 0 }
func test1() -> Int {
print("hello")
#^TestImplicitLastExprMember1?check=IMPLICIT_LAST_EXPR_MEMBER^#
}
func test2() -> Int {
print("hello")
self.#^TestImplicitLastExprMember2?check=IMPLICIT_LAST_EXPR_MEMBER^#
}
func test3() -> Int {
{
print("hello")
#^TestImplicitLastExprMember3?check=IMPLICIT_LAST_EXPR_MEMBER^#
}()
}
func test4() -> Int {
();
{
print("hello")
self.#^TestImplicitLastExprMember4?check=IMPLICIT_LAST_EXPR_MEMBER^#
}()
}
// IMPLICIT_LAST_EXPR_MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; name=void()
// IMPLICIT_LAST_EXPR_MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; name=str()
// IMPLICIT_LAST_EXPR_MEMBER-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: int()[#Int#]; name=int()
func test5() {
let fn = {
print("hello")
self.#^TestImplicitLastExprMember5?check=IMPLICIT_LAST_EXPR_MEMBER_VOID^#
}
}
func test6() {
let fn: () -> Void = {
print("hello")
#^TestImplicitLastExprMember6?check=IMPLICIT_LAST_EXPR_MEMBER_VOID^#
}
}
// IMPLICIT_LAST_EXPR_MEMBER_VOID-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; name=void()
// IMPLICIT_LAST_EXPR_MEMBER_VOID-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; name=str()
// IMPLICIT_LAST_EXPR_MEMBER_VOID-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; name=int()
}
|