Skip to content

Commit 911f7b1

Browse files
authored
[CodeCompletion] Using the default constraints generator for TupleExpr (#5557)
[CodeCompletion] Using the default constraints generator for TupleExpr when inferring the type of unresolved members. rdar://28991372 When code completing, we used to create a type variable to represent the type of an entire tuple expression. However, recent improvements on parser make this step unnecessary and crash-prone. Thus, we use the default constraint generator to interpret tuple expressions.
1 parent 3fc5aef commit 911f7b1

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ namespace {
16091609
return expr->getType();
16101610
}
16111611

1612-
virtual Type visitTupleExpr(TupleExpr *expr) {
1612+
Type visitTupleExpr(TupleExpr *expr) {
16131613
// The type of a tuple expression is simply a tuple of the types of
16141614
// its subexpressions.
16151615
SmallVector<TupleTypeElt, 4> elements;
@@ -3011,16 +3011,6 @@ class InferUnresolvedMemberConstraintGenerator : public ConstraintGenerator {
30113011
return VT = createFreeTypeVariableType(Expr);
30123012
}
30133013

3014-
Type visitTupleExpr(TupleExpr *Expr) override {
3015-
if (Target != Expr) {
3016-
// If expr is not the target, do the default constraint generation.
3017-
return ConstraintGenerator::visitTupleExpr(Expr);
3018-
}
3019-
// Otherwise, create a type variable saying we know nothing about this expr.
3020-
assert(!VT && "cannot reassign type variable.");
3021-
return VT = createFreeTypeVariableType(Expr);
3022-
}
3023-
30243014
Type visitErrorExpr(ErrorExpr *Expr) override {
30253015
return createFreeTypeVariableType(Expr);
30263016
}

test/IDE/complete_crashes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BAD_MEMBERS_1 | %FileCheck %s -check-prefix=BAD_MEMBERS_1
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BAD_MEMBERS_2 | %FileCheck %s -check-prefix=BAD_MEMBERS_2
33
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CLOSURE_CALLED_IN_PLACE_1 | %FileCheck %s -check-prefix=WITH_GLOBAL
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RDAR_28991372 | %FileCheck %s -check-prefix=RDAR_28991372
45

56
class BadMembers1 {
67
var prop: Int {
@@ -188,3 +189,10 @@ conn.handler = { (msgID, msg) in
188189
}
189190
}
190191
// RDAR_22769393: Begin completions
192+
193+
struct S_RDAR_28991372 {
194+
init(x: Int, y: Int) {}
195+
}
196+
197+
S_RDAR_28991372(x: #^RDAR_28991372^#, y: <#T##Int#>)
198+
// RDAR_28991372: Begin completions

0 commit comments

Comments
 (0)