Skip to content

Commit 517f414

Browse files
authored
Merge pull request #31079 from rintaro/5.2-ide-completion-analyzetuple-rdar61668779
[5.2][CodeCompletion] Fix a crash in context type analysis for tuple expr
2 parents fb388fb + 6e8424a commit 517f414

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ class ExprContextAnalyzer {
695695
unsigned Position = 0;
696696
bool HasName;
697697
if (getPositionInArgs(*DC, Parent, ParsedExpr, Position, HasName)) {
698-
recordPossibleType(tupleT->getElementType(Position));
698+
// The expected type may have fewer number of elements.
699+
if (Position < tupleT->getNumElements())
700+
recordPossibleType(tupleT->getElementType(Position));
699701
}
700702
break;
701703
}

test/IDE/complete_call_arg.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARCHETYPE_GENERIC_1 | %FileCheck %s -check-prefix=ARCHETYPE_GENERIC_1
9595
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_WITH_ERROR_AUTOCLOSURE| %FileCheck %s -check-prefix=PARAM_WITH_ERROR_AUTOCLOSURE
9696

97+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TUPLEELEM_1 | %FileCheck %s -check-prefix=TUPLEELEM_1
98+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TUPLEELEM_2 | %FileCheck %s -check-prefix=TUPLEELEM_2
99+
97100
var i1 = 1
98101
var i2 = 2
99102
var oi1 : Int?
@@ -751,3 +754,14 @@ struct TestHasErrorAutoclosureParam {
751754
// PARAM_WITH_ERROR_AUTOCLOSURE: End completions
752755
}
753756
}
757+
758+
func testTupleElement(arg: (SimpleEnum, SimpleEnum)) {
759+
testTupleElement(arg: (.foo, .#^TUPLEELEM_1^#))
760+
// TUPLEELEM_1: Begin completions, 3 items
761+
// TUPLEELEM_1-DAG: Decl[EnumElement]/ExprSpecific: foo[#SimpleEnum#]; name=foo
762+
// TUPLEELEM_1-DAG: Decl[EnumElement]/ExprSpecific: bar[#SimpleEnum#]; name=bar
763+
// TUPLEELEM_1-DAG: Decl[EnumElement]/ExprSpecific: baz[#SimpleEnum#]; name=baz
764+
// TUPLEELEM_1: End completions
765+
testTupleElement(arg: (.foo, .bar, .#^TUPLEELEM_2^#))
766+
// TUPLEELEM_2-NOT: Begin completions
767+
}

0 commit comments

Comments
 (0)