@@ -1231,7 +1231,15 @@ bool AllowInvalidRefInKeyPath::diagnose(const Solution &solution,
12311231 bool asNote) const {
12321232 switch (Kind) {
12331233 case RefKind::StaticMember: {
1234- return false ;
1234+ InvalidStaticMemberRefInKeyPath failure (solution, BaseType, Member,
1235+ getLocator ());
1236+ return failure.diagnose (asNote);
1237+ }
1238+
1239+ case RefKind::UnsupportedStaticMember: {
1240+ UnsupportedStaticMemberRefInKeyPath failure (solution, BaseType, Member,
1241+ getLocator ());
1242+ return failure.diagnose (asNote);
12351243 }
12361244
12371245 case RefKind::EnumCase: {
@@ -1281,12 +1289,23 @@ AllowInvalidRefInKeyPath *
12811289AllowInvalidRefInKeyPath::forRef (ConstraintSystem &cs, Type baseType,
12821290 ValueDecl *member,
12831291 ConstraintLocator *locator) {
1292+ if (member->isStatic () && !isa<FuncDecl>(member)) {
1293+ // References to static members are supported only for modules that
1294+ // are built with 6.1+ compilers, libraries produced by earlier
1295+ // compilers don't have required symbols.
1296+ if (auto *module = member->getDeclContext ()->getParentModule ()) {
1297+ if (module ->isBuiltFromInterface () &&
1298+ module ->getSwiftInterfaceCompilerVersion () <
1299+ llvm::VersionTuple (6 , 1 )) {
1300+ return AllowInvalidRefInKeyPath::create (
1301+ cs, baseType, RefKind::UnsupportedStaticMember, member, locator);
1302+ }
1303+ }
12841304
1285- if (!cs.getASTContext ().LangOpts .hasFeature (
1286- Feature::KeyPathWithStaticMembers) &&
1287- member->isStatic ())
1288- return AllowInvalidRefInKeyPath::create (cs, baseType, RefKind::StaticMember,
1289- member, locator);
1305+ if (!baseType->getRValueType ()->is <AnyMetatypeType>())
1306+ return AllowInvalidRefInKeyPath::create (
1307+ cs, baseType, RefKind::StaticMember, member, locator);
1308+ }
12901309
12911310 // Referencing (instance or static) methods in key path is
12921311 // not currently allowed.
0 commit comments