Skip to content

Commit 0299234

Browse files
committed
---
yaml --- r: 347327 b: refs/heads/master c: 39c0d00 h: refs/heads/master i: 347325: 9402a03 347323: 3363b58 347319: 3b1da64 347311: 057eddb 347295: a816f2a 347263: a9e675e
1 parent d0dec2f commit 0299234

File tree

4 files changed

+49
-26
lines changed

4 files changed

+49
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: dbca91686a31488b5bde4be64ed82237170d3645
2+
refs/heads/master: 39c0d00eeb37d678de7d1d7314627dd77762d0f4
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/IDE/CodeCompletion.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4992,19 +4992,30 @@ void CodeCompletionCallbacksImpl::doneParsing() {
49924992
bool OnRoot = !KPE->getComponents().front().isValid();
49934993
Lookup.setIsSwiftKeyPathExpr(OnRoot);
49944994

4995-
auto ParsedType = BGT->getGenericArgs()[1];
4996-
auto Components = KPE->getComponents();
4997-
if (Components.back().getKind() ==
4998-
KeyPathExpr::Component::Kind::OptionalWrap) {
4995+
Type baseType = BGT->getGenericArgs()[OnRoot ? 0 : 1];
4996+
if (OnRoot && baseType->is<UnresolvedType>()) {
4997+
// Infer the root type of the keypath from the context type.
4998+
ExprContextInfo ContextInfo(CurDeclContext, ParsedExpr);
4999+
for (auto T : ContextInfo.getPossibleTypes()) {
5000+
if (auto unwrapped = T->getOptionalObjectType())
5001+
T = unwrapped;
5002+
if (!T->getAnyNominal() || !T->getAnyNominal()->getKeyPathTypeKind() ||
5003+
T->hasUnresolvedType() || !T->is<BoundGenericType>())
5004+
continue;
5005+
// Use the first KeyPath context type found.
5006+
baseType = T->castTo<BoundGenericType>()->getGenericArgs()[0];
5007+
break;
5008+
}
5009+
}
5010+
if (!OnRoot && KPE->getComponents().back().getKind() ==
5011+
KeyPathExpr::Component::Kind::OptionalWrap) {
49995012
// KeyPath expr with '?' (e.g. '\Ty.[0].prop?.another').
50005013
// Althogh expected type is optional, we should unwrap it because it's
50015014
// unwrapped.
5002-
ParsedType = ParsedType->getOptionalObjectType();
5015+
baseType = baseType->getOptionalObjectType();
50035016
}
50045017

5005-
// The second generic type argument of KeyPath<Root, Value> should be
5006-
// the value we pull code completion results from.
5007-
Lookup.getValueExprCompletions(ParsedType);
5018+
Lookup.getValueExprCompletions(baseType);
50085019
break;
50095020
}
50105021

trunk/test/IDE/complete_constructor.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AVAILABLE_1 | %FileCheck %s -check-prefix=AVAILABLE_1
5151
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AVAILABLE_2 | %FileCheck %s -check-prefix=AVAILABLE_2
5252

53-
// REQUIRES: rdar49240981
54-
5553
func freeFunc() {}
5654

5755
//===---
@@ -92,10 +90,11 @@ func testImplicitConstructors2() {
9290
}
9391
func testImplicitConstructors2P() {
9492
ImplicitConstructors2(#^IMPLICIT_CONSTRUCTORS_2P^#
95-
// IMPLICIT_CONSTRUCTORS_2P: Begin completions
96-
// IMPLICIT_CONSTRUCTORS_2P-NEXT: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
97-
// IMPLICIT_CONSTRUCTORS_2P-NEXT: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
98-
// IMPLICIT_CONSTRUCTORS_2P-NEXT: End completions
93+
// IMPLICIT_CONSTRUCTORS_2P: Begin completions, 3 items
94+
// IMPLICIT_CONSTRUCTORS_2P-DAG: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
95+
// IMPLICIT_CONSTRUCTORS_2P-DAG: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
96+
// IMPLICIT_CONSTRUCTORS_2P-DAG: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
97+
// IMPLICIT_CONSTRUCTORS_2P: End completions
9998
}
10099

101100
struct ExplicitConstructors1 {
@@ -290,10 +289,11 @@ func testHaveRParen1() {
290289

291290
func testHaveRParen2() {
292291
ImplicitConstructors2(#^HAVE_RPAREN_2^#)
293-
// HAVE_RPAREN_2-NOT: Decl[Constructor]
294-
// HAVE_RPAREN_2: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
295-
// HAVE_RPAREN_2: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
296-
// HAVE_RPAREN_2-NOT: Decl[Constructor]
292+
// HAVE_RPAREN_2: Begin completions, 3 items
293+
// HAVE_RPAREN_2-DAG: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
294+
// HAVE_RPAREN_2-DAG: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
295+
// HAVE_RPAREN_2-DAG: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
296+
// HAVE_RPAREN_2: End completions
297297
}
298298

299299
func testHaveComma1() {

trunk/test/IDE/complete_swift_key_path.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EMPTY_2 | %FileCheck %s -check-prefix=INVALID
2222

2323
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXT_BASEONLY | %FileCheck %s -check-prefix=PERSONTYPE-DOT
24-
// FIXME: RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXT_EXPLICIT | %FileCheck %s -check-prefix=INVALID
24+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXT_EXPLICIT | %FileCheck %s -check-prefix=PERSONTYPE-DOT
25+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXT_GENERIC_RESULT | %FileCheck %s -check-prefix=PERSONTYPE-DOT
26+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONTEXT_GENERIC_RESULT_OPTIONAL | %FileCheck %s -check-prefix=PERSONTYPE-DOT
2527

2628
class Person {
2729
var name: String
@@ -131,9 +133,19 @@ let _ = \.#^EMPTY_1^#
131133
let _ = \.friends.#^EMPTY_2^#
132134
// INVALID-NOT: Begin completions
133135

134-
let _: PartialKeyPath<Person> = \.#^CONTEXT_BASEONLY^#
135-
// Same as TYPE_DOT.
136-
137-
let _: KeyPath<Person, String> = \.#^CONTEXT_EXPLICIT^#
138-
// FIXME: Currently, it's suggest nothing. Since we know the base type is
139-
// 'Person', we should suggest at least '.name'.
136+
func recvPartialKP(_ kp: PartialKeyPath<Person>) {
137+
recvPartialKP(\.#^CONTEXT_BASEONLY^#)
138+
// Same as TYPE_DOT.
139+
}
140+
func recvExplicitKP(_ kp: KeyPath<Person, String>) {
141+
recvExplicitKP(\.#^CONTEXT_EXPLICIT^#)
142+
// Same as TYPE_DOT.
143+
}
144+
func recvExplicitKPWithGenericResult<Result>(_ kp: KeyPath<Person, Result>) {
145+
recvExplicitKPWithGenericResult(\.#^CONTEXT_GENERIC_RESULT^#)
146+
// Same as TYPE_DOT.
147+
}
148+
func recvExplicitKPWithGenericResultOpt<Result>(_ kp: KeyPath<Person, Result>?) {
149+
recvExplicitKPWithGenericResult(\.#^CONTEXT_GENERIC_RESULT_OPTIONAL^#
150+
// Same as TYPE_DOT.
151+
}

0 commit comments

Comments
 (0)