Skip to content

Commit f7252d2

Browse files
committed
Fix <rdar://problem/22000564> Crash on Subscript taking a tuple argument list
by changing buildSubscriptIndexReference to work solely in terms of the parameter pattern of the subscript, instead of trying to walk the index type in parallel to extract parameter labels.
1 parent a320b6c commit f7252d2

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,18 +448,20 @@ static Expr *buildTupleExpr(ASTContext &ctx, ArrayRef<Expr*> args) {
448448

449449

450450
static Expr *buildTupleForwardingRefExpr(ASTContext &ctx,
451-
ArrayRef<TuplePatternElt> params,
452-
ArrayRef<TupleTypeElt> formalIndexTypes) {
453-
assert(params.size() == formalIndexTypes.size());
454-
451+
ArrayRef<TuplePatternElt> params) {
455452
SmallVector<Identifier, 4> labels;
456453
SmallVector<SourceLoc, 4> labelLocs;
457454
SmallVector<Expr *, 4> args;
458455

459456
for (unsigned i = 0, e = params.size(); i != e; ++i) {
460457
const Pattern *param = params[i].getPattern();
461458
args.push_back(param->buildForwardingRefExpr(ctx));
462-
labels.push_back(formalIndexTypes[i].getName());
459+
// If this parameter pattern has a name, extract it.
460+
if (auto *np =dyn_cast<NamedPattern>(param->getSemanticsProvidingPattern()))
461+
labels.push_back(np->getBoundName());
462+
else
463+
labels.push_back(Identifier());
464+
463465
labelLocs.push_back(SourceLoc());
464466
}
465467

@@ -497,14 +499,7 @@ static Expr *buildSubscriptIndexReference(ASTContext &ctx, FuncDecl *accessor) {
497499
if (accessorKind == AccessorKind::IsMaterializeForSet)
498500
params = params.slice(1);
499501

500-
// Look for formal subscript labels.
501-
auto subscript = cast<SubscriptDecl>(accessor->getAccessorStorageDecl());
502-
auto indexType = subscript->getIndicesType();
503-
if (auto indexTuple = indexType->getAs<TupleType>()) {
504-
return buildTupleForwardingRefExpr(ctx, params, indexTuple->getElements());
505-
} else {
506-
return buildTupleForwardingRefExpr(ctx, params, TupleTypeElt(indexType));
507-
}
502+
return buildTupleForwardingRefExpr(ctx, params);
508503
}
509504

510505
enum class SelfAccessKind {

test/SILGen/crashers_silgen.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -emit-silgen -o /dev/null %s
2+
3+
// <rdar://22000564> Crash on Subscript taking a tuple argument list
4+
class r22000564 {
5+
subscript (position: (Int, Int)) -> Int {
6+
get { return 32 }
7+
set {}
8+
}
9+
subscript(native native: Int) -> Int {
10+
get { return native }
11+
set {}
12+
}
13+
subscript (position position: (Int, Int)) -> Int {
14+
get { return 32 }
15+
set {}
16+
}
17+
}

0 commit comments

Comments
 (0)