@@ -712,11 +712,7 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
712
712
if (const auto boundTy = openerFn (unboundTy))
713
713
return boundTy;
714
714
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;
720
716
}
721
717
}
722
718
@@ -914,11 +910,19 @@ Type TypeResolution::applyUnboundGenericArguments(
914
910
return BoundGenericType::get (nominalDecl, parentTy, genericArgs);
915
911
}
916
912
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 ());
919
924
}
920
925
921
- subs = parentTy->getContextSubstitutions (decl->getDeclContext ());
922
926
skipRequirementsCheck |= parentTy->hasTypeVariable ();
923
927
} else if (auto genericEnv =
924
928
decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
@@ -1501,16 +1505,21 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
1501
1505
1502
1506
auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType,
1503
1507
AssociatedTypeDecl *inferredAssocType) {
1508
+ bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
1509
+
1504
1510
if (options.contains (TypeResolutionFlags::SilenceErrors)) {
1505
- if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)
1511
+ if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1512
+ hasUnboundOpener)
1506
1513
!= TypeChecker::UnsupportedMemberTypeAccessKind::None)
1507
1514
return ErrorType::get (ctx);
1508
1515
}
1509
1516
1510
- switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)) {
1517
+ switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1518
+ hasUnboundOpener)) {
1511
1519
case TypeChecker::UnsupportedMemberTypeAccessKind::None:
1512
1520
break ;
1513
1521
1522
+ case TypeChecker::UnsupportedMemberTypeAccessKind::NominalTypeOfUnboundGeneric:
1514
1523
case TypeChecker::UnsupportedMemberTypeAccessKind::TypeAliasOfUnboundGeneric:
1515
1524
case TypeChecker::UnsupportedMemberTypeAccessKind::AssociatedTypeOfUnboundGeneric:
1516
1525
diagnoseUnboundGenericType (parentTy, parentRange.End );
@@ -1630,29 +1639,44 @@ static Type
1630
1639
resolveIdentTypeComponent (TypeResolution resolution,
1631
1640
GenericParamList *silParams,
1632
1641
ArrayRef<ComponentIdentTypeRepr *> components) {
1633
- auto comp = components.back ();
1634
-
1635
1642
// 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)) {
1641
1670
1642
- // All remaining components use qualified lookup.
1671
+ if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
1672
+ diagnoseUnboundGenericType (result,
1673
+ lastComp->getNameLoc ().getBaseNameLoc ());
1674
+ }
1643
1675
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
+ }
1651
1678
1652
- // Resolve the nested type.
1653
- return resolveNestedIdentTypeComponent (resolution, silParams,
1654
- parentTy, parentRange,
1655
- comp);
1679
+ return result;
1656
1680
}
1657
1681
1658
1682
// Hack to apply context-specific @escaping to an AST function type.
0 commit comments