Skip to content

Commit d7c6887

Browse files
committed
[SILGen] Don't assert on subscripts with no index arguments.
1 parent 64a486d commit d7c6887

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,7 +5073,7 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
50735073
if (!subscripts.isNull()) {
50745074
// If we have a value and index list, create a new rvalue to represent the
50755075
// both of them together.
5076-
auto inputTupleType = cast<TupleType>(accessType.getInput());
5076+
auto inputTupleType = dyn_cast<TupleType>(accessType.getInput());
50775077

50785078
SmallVector<ArgumentSource, 4> eltSources;
50795079

@@ -5086,18 +5086,25 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
50865086
// TODO: we should really take an array of RValues.
50875087
if (accessType->getNumParams() != 2) {
50885088
auto subscriptsTupleType = cast<TupleType>(subscripts.getType());
5089-
assert(inputTupleType->getNumElements()
5089+
assert(accessType.getParams().size()
50905090
== 1 + subscriptsTupleType->getNumElements());
50915091
SmallVector<RValue, 8> eltRVs;
50925092
std::move(subscripts).extractElements(eltRVs);
50935093
for (auto &elt : eltRVs)
50945094
eltSources.emplace_back(loc, std::move(elt));
50955095
} else {
5096+
assert(inputTupleType && "Must have an input tuple here");
50965097
subscripts.rewriteType(inputTupleType.getElementType(1));
50975098
eltSources.emplace_back(loc, std::move(subscripts));
50985099
}
50995100

5100-
setValue = ArgumentSource(loc, inputTupleType, eltSources);
5101+
if (inputTupleType) {
5102+
setValue = ArgumentSource(loc, inputTupleType, eltSources);
5103+
} else {
5104+
assert(eltSources.size() == 1);
5105+
setValue = std::move(eltSources.front());
5106+
}
5107+
51015108
} else {
51025109
setValue.rewriteType(accessType.getInput());
51035110
}

test/SILGen/subscript_accessor.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen -primary-file %s | %FileCheck %s
2+
3+
// CHECK-LABEL: sil private [transparent] @$S18subscript_accessor1XVxSgycimytfU_
4+
// CHECK: [[SETTER:%.*]] = function_ref @$S18subscript_accessor1XVxSgycis
5+
// CHECK-NEXT: apply [[SETTER]]<T>
6+
struct X<T> {
7+
subscript () -> T? {
8+
get {
9+
return nil
10+
}
11+
set { }
12+
}
13+
}

0 commit comments

Comments
 (0)