@@ -713,11 +713,7 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
713
713
if (const auto boundTy = openerFn (unboundTy))
714
714
return boundTy;
715
715
716
- // Complain if we're allowed to and bail out with an error.
717
- if (!options.contains (TypeResolutionFlags::SilenceErrors))
718
- diagnoseUnboundGenericType (type, loc);
719
-
720
- return ErrorType::get (resolution.getASTContext ());
716
+ return type;
721
717
}
722
718
}
723
719
@@ -915,11 +911,19 @@ Type TypeResolution::applyUnboundGenericArguments(
915
911
return BoundGenericType::get (nominalDecl, parentTy, genericArgs);
916
912
}
917
913
918
- assert (!resultType->hasTypeParameter ());
919
- return resultType;
914
+ if (!resultType->hasTypeParameter ())
915
+ return resultType;
916
+
917
+ auto parentSig = decl->getDeclContext ()->getGenericSignatureOfContext ();
918
+ if (parentSig) {
919
+ for (auto gp : parentSig->getGenericParams ())
920
+ subs[gp->getCanonicalType ()->castTo <GenericTypeParamType>()] =
921
+ genericSig->getConcreteType (gp);
922
+ }
923
+ } else {
924
+ subs = parentTy->getContextSubstitutions (decl->getDeclContext ());
920
925
}
921
926
922
- subs = parentTy->getContextSubstitutions (decl->getDeclContext ());
923
927
skipRequirementsCheck |= parentTy->hasTypeVariable ();
924
928
} else if (auto genericEnv =
925
929
decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
@@ -1497,16 +1501,21 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
1497
1501
1498
1502
auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType,
1499
1503
AssociatedTypeDecl *inferredAssocType) {
1504
+ bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
1505
+
1500
1506
if (options.contains (TypeResolutionFlags::SilenceErrors)) {
1501
- if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)
1507
+ if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1508
+ hasUnboundOpener)
1502
1509
!= TypeChecker::UnsupportedMemberTypeAccessKind::None)
1503
1510
return ErrorType::get (ctx);
1504
1511
}
1505
1512
1506
- switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member)) {
1513
+ switch (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1514
+ hasUnboundOpener)) {
1507
1515
case TypeChecker::UnsupportedMemberTypeAccessKind::None:
1508
1516
break ;
1509
1517
1518
+ case TypeChecker::UnsupportedMemberTypeAccessKind::NominalTypeOfUnboundGeneric:
1510
1519
case TypeChecker::UnsupportedMemberTypeAccessKind::TypeAliasOfUnboundGeneric:
1511
1520
case TypeChecker::UnsupportedMemberTypeAccessKind::AssociatedTypeOfUnboundGeneric:
1512
1521
diagnoseUnboundGenericType (parentTy, parentRange.End );
@@ -1626,29 +1635,44 @@ static Type
1626
1635
resolveIdentTypeComponent (TypeResolution resolution,
1627
1636
GenericParamList *silParams,
1628
1637
ArrayRef<ComponentIdentTypeRepr *> components) {
1629
- auto comp = components.back ();
1630
-
1631
1638
// The first component uses unqualified lookup.
1632
- const auto parentComps = components.drop_back ();
1633
- if (parentComps.empty ()) {
1634
- return resolveTopLevelIdentTypeComponent (resolution, silParams,
1635
- comp);
1636
- }
1639
+ auto topLevelComp = components.front ();
1640
+ auto result = resolveTopLevelIdentTypeComponent (resolution, silParams,
1641
+ topLevelComp);
1642
+ if (result->hasError ())
1643
+ return ErrorType::get (result->getASTContext ());
1644
+
1645
+ // Remaining components are resolved via iterated qualified lookups.
1646
+ SourceRange parentRange (topLevelComp->getStartLoc (),
1647
+ topLevelComp->getEndLoc ());
1648
+ for (auto nestedComp : components.drop_front ()) {
1649
+ result = resolveNestedIdentTypeComponent (resolution, silParams,
1650
+ result, parentRange,
1651
+ nestedComp);
1652
+ if (result->hasError ())
1653
+ return ErrorType::get (result->getASTContext ());
1654
+
1655
+ parentRange.End = nestedComp->getEndLoc ();
1656
+ }
1657
+
1658
+ // Diagnose an error if the last component's generic arguments are missing.
1659
+ auto lastComp = components.back ();
1660
+ auto options = resolution.getOptions ();
1661
+
1662
+ if (result->is <UnboundGenericType>() &&
1663
+ !isa<GenericIdentTypeRepr>(lastComp) &&
1664
+ !resolution.getUnboundTypeOpener () &&
1665
+ !options.is (TypeResolverContext::TypeAliasDecl)) {
1637
1666
1638
- // All remaining components use qualified lookup.
1667
+ if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
1668
+ diagnoseUnboundGenericType (result,
1669
+ lastComp->getNameLoc ().getBaseNameLoc ());
1670
+ }
1639
1671
1640
- // Resolve the parent type.
1641
- Type parentTy = resolveIdentTypeComponent (resolution, silParams,
1642
- parentComps);
1643
- if (!parentTy || parentTy->hasError ()) return parentTy;
1644
-
1645
- SourceRange parentRange (parentComps.front ()->getStartLoc (),
1646
- parentComps.back ()->getEndLoc ());
1672
+ return ErrorType::get (result->getASTContext ());
1673
+ }
1647
1674
1648
- // Resolve the nested type.
1649
- return resolveNestedIdentTypeComponent (resolution, silParams,
1650
- parentTy, parentRange,
1651
- comp);
1675
+ return result;
1652
1676
}
1653
1677
1654
1678
// Hack to apply context-specific @escaping to an AST function type.
0 commit comments