@@ -1251,6 +1251,11 @@ bool AllowInvalidRefInKeyPath::diagnose(const Solution &solution,
1251
1251
getLocator ());
1252
1252
return failure.diagnose (asNote);
1253
1253
}
1254
+ case RefKind::Method:
1255
+ case RefKind::Initializer: {
1256
+ UnsupportedMethodRefInKeyPath failure (solution, Member, getLocator ());
1257
+ return failure.diagnose (asNote);
1258
+ }
1254
1259
case RefKind::MutatingMethod: {
1255
1260
InvalidMutatingMethodRefInKeyPath failure (solution, Member, getLocator ());
1256
1261
return failure.diagnose (asNote);
@@ -1323,22 +1328,41 @@ AllowInvalidRefInKeyPath::forRef(ConstraintSystem &cs, Type baseType,
1323
1328
cs, baseType, RefKind::MutatingGetter, member, locator);
1324
1329
}
1325
1330
1326
- // Referencing mutating, throws or async method members is not currently
1327
- // allowed.
1328
- if (auto method = dyn_cast<FuncDecl>(member)) {
1329
- if (method->isAsyncContext ())
1330
- return AllowInvalidRefInKeyPath::create (
1331
- cs, baseType, RefKind::AsyncOrThrowsMethod, member, locator);
1332
- if (auto methodType = method->getInterfaceType ()->getAs <AnyFunctionType>()) {
1333
- if (methodType->getResult ()->getAs <AnyFunctionType>()->isThrowing ())
1331
+ if (cs.getASTContext ().LangOpts .hasFeature (
1332
+ Feature::KeyPathWithMethodMembers)) {
1333
+ // Referencing mutating, throws or async method members is not currently
1334
+ // allowed.
1335
+ if (auto method = dyn_cast<FuncDecl>(member)) {
1336
+ if (method->isAsyncContext ())
1334
1337
return AllowInvalidRefInKeyPath::create (
1335
1338
cs, baseType, RefKind::AsyncOrThrowsMethod, member, locator);
1339
+ if (auto methodType =
1340
+ method->getInterfaceType ()->getAs <AnyFunctionType>()) {
1341
+ if (methodType->getResult ()->getAs <AnyFunctionType>()->isThrowing ())
1342
+ return AllowInvalidRefInKeyPath::create (
1343
+ cs, baseType, RefKind::AsyncOrThrowsMethod, member, locator);
1344
+ }
1345
+ if (method->isMutating ())
1346
+ return AllowInvalidRefInKeyPath::create (
1347
+ cs, baseType, RefKind::MutatingMethod, member, locator);
1348
+ return nullptr ;
1336
1349
}
1337
- if (method-> isMutating ())
1338
- return AllowInvalidRefInKeyPath::create (
1339
- cs, baseType, RefKind::MutatingMethod, member, locator) ;
1350
+
1351
+ if (isa<ConstructorDecl>(member))
1352
+ return nullptr ;
1340
1353
}
1341
1354
1355
+ // Referencing (instance or static) methods in key path is
1356
+ // not currently allowed.
1357
+ if (isa<FuncDecl>(member))
1358
+ return AllowInvalidRefInKeyPath::create (cs, baseType, RefKind::Method,
1359
+ member, locator);
1360
+
1361
+ // Referencing initializers in key path is not currently allowed.
1362
+ if (isa<ConstructorDecl>(member))
1363
+ return AllowInvalidRefInKeyPath::create (cs, baseType, RefKind::Initializer,
1364
+ member, locator);
1365
+
1342
1366
return nullptr ;
1343
1367
}
1344
1368
0 commit comments