Skip to content

Commit 3aa7082

Browse files
authored
Merge pull request swiftlang#28465 from zoecarver/feature/variadic-args-key-path-subscript
Fix variadic args in key path subscript
2 parents 19395d6 + 88f9c67 commit 3aa7082

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,7 +4571,7 @@ namespace {
45714571
for (auto &param : fnType->getParams()) {
45724572
newLabels.push_back(param.getLabel());
45734573

4574-
auto indexType = simplifyType(param.getPlainType());
4574+
auto indexType = simplifyType(param.getParameterType());
45754575
// Index type conformance to Hashable protocol has been
45764576
// verified by the solver, we just need to get it again
45774577
// with all of the generic parameters resolved.

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
22812281
// Hashable, because it would be used as a component inside key path.
22822282
for (auto index : indices(subscriptTy->getParams())) {
22832283
const auto &param = subscriptTy->getParams()[index];
2284-
verifyThatArgumentIsHashable(index, param.getPlainType(), locator);
2284+
verifyThatArgumentIsHashable(index, param.getParameterType(), locator);
22852285
}
22862286
}
22872287
}

test/SILGen/keypaths.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,53 @@ func check_default_subscripts() {
452452
_ = \SubscriptDefaults5.[x: "", y: ""]
453453
}
454454

455+
struct SubscriptVariadic1 {
456+
subscript(x: Int...) -> Int { x[0] }
457+
}
458+
459+
struct SubscriptVariadic2 {
460+
subscript<T : ExpressibleByStringLiteral>(x: T...) -> T { x[0] }
461+
}
462+
463+
struct SubscriptVariadic3<T : ExpressibleByStringLiteral> {
464+
subscript(x: T...) -> T { x[0] }
465+
}
466+
467+
// CHECK-LABEL: sil hidden [ossa] @{{.*}}test_variadics
468+
func test_variadics() {
469+
// CHECK: [[ARR_COUNT:%[0-9]+]] = integer_literal $Builtin.Word, 3
470+
// CHECK: [[FN_REF:%[0-9]+]] = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF
471+
// CHECK: [[MAKE_ARR:%[0-9]+]] = apply [[FN_REF]]<Int>([[ARR_COUNT]])
472+
// CHECK: ([[ARR:%[0-9]+]], %{{[0-9]+}}) = destructure_tuple [[MAKE_ARR]] : $(Array<Int>, Builtin.RawPointer)
473+
// CHECK: keypath $KeyPath<SubscriptVariadic1, Int>, (root $SubscriptVariadic1; gettable_property $Int, id @$s8keypaths18SubscriptVariadic1VyS2id_tcig : $@convention(method) (@guaranteed Array<Int>, SubscriptVariadic1) -> Int, getter @$s8keypaths18SubscriptVariadic1VyS2id_tcipACTK : $@convention(thin) (@in_guaranteed SubscriptVariadic1, UnsafeRawPointer) -> @out Int, indices [%$0 : $Array<Int> : $Array<Int>], indices_equals @$sSaySiGTH : $@convention(thin) (UnsafeRawPointer, UnsafeRawPointer) -> Bool, indices_hash @$sSaySiGTh : $@convention(thin) (UnsafeRawPointer) -> Int) ([[ARR]])
474+
_ = \SubscriptVariadic1.[1, 2, 3]
475+
// CHECK: [[ARR_COUNT:%[0-9]+]] = integer_literal $Builtin.Word, 1
476+
// CHECK: [[FN_REF:%[0-9]+]] = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF
477+
// CHECK: [[MAKE_ARR:%[0-9]+]] = apply [[FN_REF]]<Int>([[ARR_COUNT]])
478+
// CHECK: ([[ARR:%[0-9]+]], %{{[0-9]+}}) = destructure_tuple [[MAKE_ARR]] : $(Array<Int>, Builtin.RawPointer)
479+
// CHECK: keypath $KeyPath<SubscriptVariadic1, Int>, (root $SubscriptVariadic1; gettable_property $Int, id @$s8keypaths18SubscriptVariadic1VyS2id_tcig : $@convention(method) (@guaranteed Array<Int>, SubscriptVariadic1) -> Int, getter @$s8keypaths18SubscriptVariadic1VyS2id_tcipACTK : $@convention(thin) (@in_guaranteed SubscriptVariadic1, UnsafeRawPointer) -> @out Int, indices [%$0 : $Array<Int> : $Array<Int>], indices_equals @$sSaySiGTH : $@convention(thin) (UnsafeRawPointer, UnsafeRawPointer) -> Bool, indices_hash @$sSaySiGTh : $@convention(thin) (UnsafeRawPointer) -> Int) ([[ARR]])
480+
_ = \SubscriptVariadic1.[1]
481+
// CHECK: [[ARR_COUNT:%[0-9]+]] = integer_literal $Builtin.Word, 0
482+
// CHECK: [[FN_REF:%[0-9]+]] = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF
483+
// CHECK: [[MAKE_ARR:%[0-9]+]] = apply [[FN_REF]]<Int>([[ARR_COUNT]])
484+
// CHECK: ([[ARR:%[0-9]+]], %{{[0-9]+}}) = destructure_tuple [[MAKE_ARR]] : $(Array<Int>, Builtin.RawPointer)
485+
// CHECK: keypath $KeyPath<SubscriptVariadic1, Int>, (root $SubscriptVariadic1; gettable_property $Int, id @$s8keypaths18SubscriptVariadic1VyS2id_tcig : $@convention(method) (@guaranteed Array<Int>, SubscriptVariadic1) -> Int, getter @$s8keypaths18SubscriptVariadic1VyS2id_tcipACTK : $@convention(thin) (@in_guaranteed SubscriptVariadic1, UnsafeRawPointer) -> @out Int, indices [%$0 : $Array<Int> : $Array<Int>], indices_equals @$sSaySiGTH : $@convention(thin) (UnsafeRawPointer, UnsafeRawPointer) -> Bool, indices_hash @$sSaySiGTh : $@convention(thin) (UnsafeRawPointer) -> Int) ([[ARR]])
486+
_ = \SubscriptVariadic1.[]
487+
488+
_ = \SubscriptVariadic2.["", "1"]
489+
_ = \SubscriptVariadic2.[""]
490+
// CHECK: [[ARR_COUNT:%[0-9]+]] = integer_literal $Builtin.Word, 2
491+
// CHECK: [[FN_REF:%[0-9]+]] = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF
492+
// CHECK: [[MAKE_ARR:%[0-9]+]] = apply [[FN_REF]]<String>([[ARR_COUNT]])
493+
// CHECK: ([[ARR:%[0-9]+]], %{{[0-9]+}}) = destructure_tuple [[MAKE_ARR]] : $(Array<String>, Builtin.RawPointer)
494+
// CHECK: keypath $KeyPath<SubscriptVariadic2, String>, (root $SubscriptVariadic2; gettable_property $String, id @$s8keypaths18SubscriptVariadic2Vyxxd_tcs26ExpressibleByStringLiteralRzluig : $@convention(method) <τ_0_0 where τ_0_0 : ExpressibleByStringLiteral> (@guaranteed Array<τ_0_0>, SubscriptVariadic2) -> @out τ_0_0, getter @$s8keypaths18SubscriptVariadic2Vyxxd_tcs26ExpressibleByStringLiteralRzluipACSSTK : $@convention(thin) (@in_guaranteed SubscriptVariadic2, UnsafeRawPointer) -> @out String, indices [%$0 : $Array<String> : $Array<String>], indices_equals @$sSaySSGTH : $@convention(thin) (UnsafeRawPointer, UnsafeRawPointer) -> Bool, indices_hash @$sSaySSGTh : $@convention(thin) (UnsafeRawPointer) -> Int) ([[ARR]])
495+
_ = \SubscriptVariadic2.["", #function]
496+
497+
_ = \SubscriptVariadic3<String>.[""]
498+
_ = \SubscriptVariadic3<String>.["", "1"]
499+
_ = \SubscriptVariadic3<String>.[]
500+
}
501+
455502
// CHECK-LABEL: sil hidden [ossa] @{{.*}}subclass_generics
456503
func subclass_generics<T: C<Int>, U: C<V>, V/*: PoC*/>(_: T, _: U, _: V) {
457504
_ = \T.x

0 commit comments

Comments
 (0)