Skip to content

Commit 53b0976

Browse files
Azoymeg-gupta
authored andcommitted
Fix tuple keypath verifier (swiftlang#60737)
1 parent 0815498 commit 53b0976

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,19 @@ void verifyKeyPathComponent(SILModule &M,
418418
break;
419419
}
420420
case KeyPathPatternComponent::Kind::TupleElement: {
421-
require(loweredBaseTy.is<TupleType>(),
421+
require(baseTy->is<TupleType>(),
422422
"invalid baseTy, should have been a TupleType");
423423

424-
auto tupleTy = loweredBaseTy.castTo<TupleType>();
424+
auto tupleTy = baseTy->castTo<TupleType>();
425425
auto eltIdx = component.getTupleIndex();
426426

427427
require(eltIdx < tupleTy->getNumElements(),
428428
"invalid element index, greater than # of tuple elements");
429429

430-
auto eltTy = tupleTy.getElementType(eltIdx)
431-
.getReferenceStorageReferent();
430+
auto eltTy = tupleTy->getElementType(eltIdx)
431+
->getReferenceStorageReferent();
432432

433-
require(eltTy == componentTy,
433+
require(eltTy->isEqual(componentTy),
434434
"tuple element type should match the type of the component");
435435

436436
break;

test/SILGen/keypaths.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ func tuples(_: T) {
572572
let _: ReferenceWritableKeyPath<T, Int> = \T.c.x.x
573573
// CHECK: keypath $KeyPath<T, String>, (root $T; stored_property #T.c : $(x: C<Int>, y: C<String>); tuple_element #0 : $C<Int>; stored_property #C.y : $String)
574574
let _: KeyPath<T, String> = \T.c.x.y
575+
576+
typealias Thing = (type: Any.Type, fn: () -> ())
577+
578+
// CHECK: keypath $WritableKeyPath<(type: any Any.Type, fn: () -> ()), any Any.Type>, (root $(type: any Any.Type, fn: () -> ()); tuple_element #0 : $any Any.Type)
579+
let _: WritableKeyPath<Thing, Any.Type> = \Thing.type
580+
581+
// CHECK: keypath $WritableKeyPath<(type: any Any.Type, fn: () -> ()), () -> ()>, (root $(type: any Any.Type, fn: () -> ()); tuple_element #1 : $() -> ())
582+
let _: WritableKeyPath<Thing, () -> ()> = \Thing.fn
575583
}
576584

577585
// CHECK-LABEL: sil hidden [ossa] @{{.*}}tuples_generic

0 commit comments

Comments
 (0)