Skip to content

Commit 85df714

Browse files
committed
Fixed 'kind' check in KeyPathExpr::Component constructor
1 parent bcb08d0 commit 85df714

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4861,7 +4861,7 @@ class KeyPathExpr : public Expr {
48614861
Expr *indexExpr,
48624862
ArrayRef<Identifier> subscriptLabels,
48634863
ArrayRef<ProtocolConformanceRef> indexHashables,
4864-
unsigned fieldNumber,
4864+
unsigned tupleIndex,
48654865
Kind kind,
48664866
Type type,
48674867
SourceLoc loc);

lib/AST/Expr.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ KeyPathExpr::Component::Component(ASTContext *ctxForCopyingLabels,
21852185
Expr *indexExpr,
21862186
ArrayRef<Identifier> subscriptLabels,
21872187
ArrayRef<ProtocolConformanceRef> indexHashables,
2188-
unsigned fieldNumber,
2188+
unsigned tupleIndex,
21892189
Kind kind,
21902190
Type type,
21912191
SourceLoc loc)
@@ -2194,13 +2194,15 @@ KeyPathExpr::Component::Component(ASTContext *ctxForCopyingLabels,
21942194
{
21952195
assert(subscriptLabels.size() == indexHashables.size()
21962196
|| indexHashables.empty());
2197-
assert(subscriptLabels.empty() || fieldNumber == 0);
21982197
SubscriptLabelsData = subscriptLabels.data();
21992198
SubscriptHashableConformancesData = indexHashables.empty()
22002199
? nullptr : indexHashables.data();
2200+
2201+
if (kind == Kind::TupleElement) {
2202+
assert(subscriptLabels.empty()
2203+
&& "subscript labels not empty for tuple element");
22012204

2202-
if (subscriptLabels.empty()) {
2203-
TupleIndex = fieldNumber;
2205+
TupleIndex = tupleIndex;
22042206
} else {
22052207
SubscriptSize = subscriptLabels.size();
22062208
}

0 commit comments

Comments
 (0)