@@ -712,11 +712,7 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
712712 if (const auto boundTy = openerFn (unboundTy))
713713 return boundTy;
714714
715- // Complain if we're allowed to and bail out with an error.
716- if (!options.contains (TypeResolutionFlags::SilenceErrors))
717- diagnoseUnboundGenericType (type, loc);
718-
719- return ErrorType::get (resolution.getASTContext ());
715+ return type;
720716 }
721717 }
722718
@@ -914,11 +910,19 @@ Type TypeResolution::applyUnboundGenericArguments(
914910 return BoundGenericType::get (nominalDecl, parentTy, genericArgs);
915911 }
916912
917- assert (!resultType->hasTypeParameter ());
918- return resultType;
913+ if (!resultType->hasTypeParameter ())
914+ return resultType;
915+
916+ auto parentSig = decl->getDeclContext ()->getGenericSignatureOfContext ();
917+ if (parentSig) {
918+ for (auto gp : parentSig->getGenericParams ())
919+ subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
920+ genericSig->getConcreteType (gp);
921+ }
922+ } else {
923+ subs = parentTy->getContextSubstitutions (decl->getDeclContext ());
919924 }
920925
921- subs = parentTy->getContextSubstitutions (decl->getDeclContext ());
922926 skipRequirementsCheck |= parentTy->hasTypeVariable ();
923927 } else if (auto genericEnv =
924928 decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
@@ -1501,16 +1505,21 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
15011505
15021506 auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType,
15031507 AssociatedTypeDecl *inferredAssocType) {
1508+ bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
1509+
15041510 if (options.contains (TypeResolutionFlags::SilenceErrors)) {
1505- if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)
1511+ if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1512+ hasUnboundOpener)
15061513 != TypeChecker::UnsupportedMemberTypeAccessKind::None)
15071514 return ErrorType::get (ctx);
15081515 }
15091516
1510- switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)) {
1517+ switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1518+ hasUnboundOpener)) {
15111519 case TypeChecker::UnsupportedMemberTypeAccessKind::None:
15121520 break ;
15131521
1522+ case TypeChecker::UnsupportedMemberTypeAccessKind::NominalTypeOfUnboundGeneric:
15141523 case TypeChecker::UnsupportedMemberTypeAccessKind::TypeAliasOfUnboundGeneric:
15151524 case TypeChecker::UnsupportedMemberTypeAccessKind::AssociatedTypeOfUnboundGeneric:
15161525 diagnoseUnboundGenericType (parentTy, parentRange.End );
@@ -1630,29 +1639,44 @@ static Type
16301639resolveIdentTypeComponent (TypeResolution resolution,
16311640 GenericParamList *silParams,
16321641 ArrayRef<ComponentIdentTypeRepr *> components) {
1633- auto comp = components.back ();
1634-
16351642 // The first component uses unqualified lookup.
1636- const auto parentComps = components.drop_back ();
1637- if (parentComps.empty ()) {
1638- return resolveTopLevelIdentTypeComponent (resolution, silParams,
1639- comp);
1640- }
1643+ auto topLevelComp = components.front ();
1644+ auto result = resolveTopLevelIdentTypeComponent (resolution, silParams,
1645+ topLevelComp);
1646+ if (result->hasError ())
1647+ return ErrorType::get (result->getASTContext ());
1648+
1649+ // Remaining components are resolved via iterated qualified lookups.
1650+ SourceRange parentRange (topLevelComp->getStartLoc (),
1651+ topLevelComp->getEndLoc ());
1652+ for (auto nestedComp : components.drop_front ()) {
1653+ result = resolveNestedIdentTypeComponent (resolution, silParams,
1654+ result, parentRange,
1655+ nestedComp);
1656+ if (result->hasError ())
1657+ return ErrorType::get (result->getASTContext ());
1658+
1659+ parentRange.End = nestedComp->getEndLoc ();
1660+ }
1661+
1662+ // Diagnose an error if the last component's generic arguments are missing.
1663+ auto lastComp = components.back ();
1664+ auto options = resolution.getOptions ();
1665+
1666+ if (result->is <UnboundGenericType>() &&
1667+ !isa<GenericIdentTypeRepr>(lastComp) &&
1668+ !resolution.getUnboundTypeOpener () &&
1669+ !options.is (TypeResolverContext::TypeAliasDecl)) {
16411670
1642- // All remaining components use qualified lookup.
1671+ if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
1672+ diagnoseUnboundGenericType (result,
1673+ lastComp->getNameLoc ().getBaseNameLoc ());
1674+ }
16431675
1644- // Resolve the parent type.
1645- Type parentTy = resolveIdentTypeComponent (resolution, silParams,
1646- parentComps);
1647- if (!parentTy || parentTy->hasError ()) return parentTy;
1648-
1649- SourceRange parentRange (parentComps.front ()->getStartLoc (),
1650- parentComps.back ()->getEndLoc ());
1676+ return ErrorType::get (result->getASTContext ());
1677+ }
16511678
1652- // Resolve the nested type.
1653- return resolveNestedIdentTypeComponent (resolution, silParams,
1654- parentTy, parentRange,
1655- comp);
1679+ return result;
16561680}
16571681
16581682// Hack to apply context-specific @escaping to an AST function type.
0 commit comments