Skip to content

Commit fe5d221

Browse files
committed
[SILGen] Fix no-parameter subscript accessor emission more thoroughly.
1 parent d68a695 commit fe5d221

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5098,11 +5098,11 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
50985098
eltSources.emplace_back(loc, std::move(subscripts));
50995099
}
51005100

5101-
if (inputTupleType) {
5102-
setValue = ArgumentSource(loc, inputTupleType, eltSources);
5103-
} else {
5104-
assert(eltSources.size() == 1);
5101+
if (eltSources.size() == 1) {
51055102
setValue = std::move(eltSources.front());
5103+
} else {
5104+
assert(inputTupleType);
5105+
setValue = ArgumentSource(loc, inputTupleType, eltSources);
51065106
}
51075107

51085108
} else {

test/SILGen/subscript_accessor.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen -primary-file %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -enable-sil-ownership -O -emit-silgen -primary-file %s | %FileCheck %s
22

33
// CHECK-LABEL: sil private [transparent] @$S18subscript_accessor1XVxSgycimytfU_
44
// CHECK: [[SETTER:%.*]] = function_ref @$S18subscript_accessor1XVxSgycis
@@ -11,3 +11,9 @@ struct X<T> {
1111
set { }
1212
}
1313
}
14+
15+
// CHECK: sil{{.*}}S18subscript_accessor9testXRead1xxAA1XVyxG_tlF
16+
@_specialize(where T == (Int, Int))
17+
func testXRead<T>(x: X<T>) -> T {
18+
return x[]!
19+
}

0 commit comments

Comments
 (0)