Skip to content

Commit 7685f7f

Browse files
committed
[code-complete] Update literal protocol to show "" for Character
... and UnicodeScalar, which is technically more correct than only showing it for String. This also happens to workaround a bug where we won't show "" for string.contains. rdar://problem/34746368
1 parent d558168 commit 7685f7f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ protocolForLiteralKind(CodeCompletionLiteralKind kind) {
15211521
case CodeCompletionLiteralKind::NilLiteral:
15221522
return KnownProtocolKind::ExpressibleByNilLiteral;
15231523
case CodeCompletionLiteralKind::StringLiteral:
1524-
return KnownProtocolKind::ExpressibleByStringLiteral;
1524+
return KnownProtocolKind::ExpressibleByUnicodeScalarLiteral;
15251525
case CodeCompletionLiteralKind::Tuple:
15261526
llvm_unreachable("no such protocol kind");
15271527
}

test/IDE/complete_value_literals.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_0 | %FileCheck %s -check-prefix=STRING_0
1515
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_1 | %FileCheck %s -check-prefix=STRING_1
1616
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_2 | %FileCheck %s -check-prefix=STRING_2
17+
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_3 | %FileCheck %s -check-prefix=STRING_3
18+
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_4 | %FileCheck %s -check-prefix=STRING_4
19+
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=STRING_5 | %FileCheck %s -check-prefix=STRING_5
1720
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=ARRAY_0 | %FileCheck %s -check-prefix=ARRAY_0
1821
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=ARRAY_1 | %FileCheck %s -check-prefix=ARRAY_1
1922
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=ARRAY_2 | %FileCheck %s -check-prefix=ARRAY_2
@@ -62,6 +65,13 @@ struct MyString1: ExpressibleByStringLiteral {
6265
init(extendedGraphemeClusterLiteral value: String) {}
6366
init(stringLiteral value: String) {}
6467
}
68+
struct MyUnicodeScalar1: ExpressibleByUnicodeScalarLiteral {
69+
init(unicodeScalarLiteral value: Character) {}
70+
}
71+
struct MyCharacter1: ExpressibleByExtendedGraphemeClusterLiteral {
72+
init(unicodeScalarLiteral value: Character) {}
73+
init(extendedGraphemeClusterLiteral value: String) {}
74+
}
6575
struct MyArray1<Element>: ExpressibleByArrayLiteral {
6676
init(arrayLiteral value: Element...) {}
6777
}
@@ -154,6 +164,19 @@ func testString2() {
154164
}
155165
// STRING_2: Literal[String]/None/TypeRelation[Identical]: "{#(abc)#}"[#String#];
156166

167+
func testString3() {
168+
let x: MyUnicodeScalar1 = #^STRING_3^#
169+
}
170+
// STRING_3: Literal[String]/None/TypeRelation[Identical]: "{#(abc)#}"[#MyUnicodeScalar1#];
171+
func testString4() {
172+
let x: MyCharacter1 = #^STRING_4^#
173+
}
174+
// STRING_4: Literal[String]/None/TypeRelation[Identical]: "{#(abc)#}"[#MyCharacter1#];
175+
func testString5() {
176+
let x: Character = #^STRING_5^#
177+
}
178+
// STRING_5: Literal[String]/None/TypeRelation[Identical]: "{#(abc)#}"[#Character#];
179+
157180
func testArray0() {
158181
let x: Int = #^ARRAY_0^#
159182
}

0 commit comments

Comments
 (0)