File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -1316,9 +1316,16 @@ namespace {
1316
1316
if (choice.getKind () == OverloadChoiceKind::KeyPathApplication) {
1317
1317
index = cs.coerceToRValue (index);
1318
1318
// The index argument should be (keyPath: KeyPath<Root, Value>).
1319
- auto keyPathTTy = cs.getType (index)->castTo <TupleType>()
1320
- ->getElementType (0 );
1321
-
1319
+ // Dig the key path expression out of the argument tuple.
1320
+ auto indexKP = cast<TupleExpr>(index)->getElement (0 );
1321
+ auto keyPathTTy = cs.getType (indexKP);
1322
+
1323
+ // Check for the KeyPath being an IUO
1324
+ if (auto pathTy = cs.lookThroughImplicitlyUnwrappedOptionalType (keyPathTTy)) {
1325
+ keyPathTTy = pathTy;
1326
+ indexKP = coerceImplicitlyUnwrappedOptionalToValue (indexKP, keyPathTTy, locator);
1327
+ }
1328
+
1322
1329
Type valueTy;
1323
1330
Type baseTy;
1324
1331
bool resultIsLValue;
@@ -1376,9 +1383,6 @@ namespace {
1376
1383
if (resultIsLValue)
1377
1384
valueTy = LValueType::get (valueTy);
1378
1385
1379
- // Dig the key path expression out of the argument tuple.
1380
- auto indexKP = cast<TupleExpr>(index)->getElement (0 );
1381
-
1382
1386
auto keyPathAp = new (cs.getASTContext ())
1383
1387
KeyPathApplicationExpr (base, index->getStartLoc (), indexKP,
1384
1388
index->getEndLoc (), valueTy,
Original file line number Diff line number Diff line change @@ -376,6 +376,11 @@ class CC {
376
376
func testKeyPathOptional( ) {
377
377
_ = \AA . c? . i
378
378
_ = \AA . c!. i
379
+
380
+ // SR-6198
381
+ let path : KeyPath < CC , Int > ! = \CC . i
382
+ let cc = CC ( )
383
+ _ = cc [ keyPath: path]
379
384
}
380
385
381
386
func testLiteralInAnyContext( ) {
You can’t perform that action at this time.
0 commit comments