@@ -1492,6 +1492,7 @@ static void diagnoseGenericArgumentsOnSelf(TypeResolution resolution,
1492
1492
1493
1493
// / Resolve the given identifier type representation as an unqualified type,
1494
1494
// / returning the type it references.
1495
+ // / \param silParams Used to look up generic parameters in SIL mode.
1495
1496
// /
1496
1497
// / \returns Either the resolved type or a null type, the latter of
1497
1498
// / which indicates that some dependencies were unsatisfied.
@@ -1821,61 +1822,6 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
1821
1822
return maybeDiagnoseBadMemberType (member, memberType, inferredAssocType);
1822
1823
}
1823
1824
1824
- // / \param silParams Used to look up generic parameters in SIL mode.
1825
- static Type
1826
- resolveIdentTypeComponent (TypeResolution resolution,
1827
- GenericParamList *silParams,
1828
- ArrayRef<ComponentIdentTypeRepr *> components) {
1829
- // The first component uses unqualified lookup.
1830
- auto topLevelComp = components.front ();
1831
- auto result = resolveTopLevelIdentTypeComponent (resolution, silParams,
1832
- topLevelComp);
1833
- if (result->hasError ())
1834
- return ErrorType::get (result->getASTContext ());
1835
-
1836
- // Remaining components are resolved via iterated qualified lookups.
1837
- SourceRange parentRange (topLevelComp->getStartLoc (),
1838
- topLevelComp->getEndLoc ());
1839
- for (auto nestedComp : components.drop_front ()) {
1840
- result = resolveNestedIdentTypeComponent (resolution, silParams,
1841
- result, parentRange,
1842
- nestedComp);
1843
- if (result->hasError ())
1844
- return ErrorType::get (result->getASTContext ());
1845
-
1846
- parentRange.End = nestedComp->getEndLoc ();
1847
- }
1848
-
1849
- // Diagnose an error if the last component's generic arguments are missing.
1850
- auto lastComp = components.back ();
1851
- auto options = resolution.getOptions ();
1852
-
1853
- if (result->is <UnboundGenericType>() &&
1854
- !isa<GenericIdentTypeRepr>(lastComp) &&
1855
- !resolution.getUnboundTypeOpener () &&
1856
- !options.is (TypeResolverContext::TypeAliasDecl) &&
1857
- !options.is (TypeResolverContext::ExtensionBinding)) {
1858
-
1859
- if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
1860
- // Tailored diagnostic for custom attributes.
1861
- if (options.is (TypeResolverContext::CustomAttr)) {
1862
- auto &ctx = resolution.getASTContext ();
1863
- ctx.Diags .diagnose (lastComp->getNameLoc (), diag::unknown_attribute,
1864
- lastComp->getNameRef ().getBaseIdentifier ().str ());
1865
-
1866
- return ErrorType::get (ctx);
1867
- }
1868
-
1869
- diagnoseUnboundGenericType (result,
1870
- lastComp->getNameLoc ().getBaseNameLoc ());
1871
- }
1872
-
1873
- return ErrorType::get (result->getASTContext ());
1874
- }
1875
-
1876
- return result;
1877
- }
1878
-
1879
1825
// Hack to apply context-specific @escaping to an AST function type.
1880
1826
static Type applyNonEscapingIfNecessary (Type ty,
1881
1827
TypeResolutionOptions options) {
@@ -3866,10 +3812,50 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3866
3812
Components = cast<CompoundIdentTypeRepr>(IdType)->getComponents ();
3867
3813
}
3868
3814
3869
- Type result = resolveIdentTypeComponent (resolution.withOptions (options),
3870
- genericParams, Components);
3871
- if (!result || result->hasError ()) {
3872
- return ErrorType::get (getASTContext ());
3815
+ // The first component uses unqualified lookup.
3816
+ auto topLevelComp = Components.front ();
3817
+ auto result = resolveTopLevelIdentTypeComponent (
3818
+ resolution.withOptions (options), genericParams, topLevelComp);
3819
+ if (result->hasError ())
3820
+ return ErrorType::get (result->getASTContext ());
3821
+
3822
+ // Remaining components are resolved via iterated qualified lookups.
3823
+ SourceRange parentRange (topLevelComp->getStartLoc (),
3824
+ topLevelComp->getEndLoc ());
3825
+ for (auto nestedComp : Components.drop_front ()) {
3826
+ result = resolveNestedIdentTypeComponent (resolution.withOptions (options),
3827
+ genericParams, result, parentRange,
3828
+ nestedComp);
3829
+ if (result->hasError ())
3830
+ return ErrorType::get (result->getASTContext ());
3831
+
3832
+ parentRange.End = nestedComp->getEndLoc ();
3833
+ }
3834
+
3835
+ auto lastComp = Components.back ();
3836
+
3837
+ // Diagnose an error if the last component's generic arguments are missing.
3838
+ if (result->is <UnboundGenericType>() &&
3839
+ !isa<GenericIdentTypeRepr>(lastComp) &&
3840
+ !resolution.getUnboundTypeOpener () &&
3841
+ !options.is (TypeResolverContext::TypeAliasDecl) &&
3842
+ !options.is (TypeResolverContext::ExtensionBinding)) {
3843
+
3844
+ if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
3845
+ // Tailored diagnostic for custom attributes.
3846
+ if (options.is (TypeResolverContext::CustomAttr)) {
3847
+ auto &ctx = resolution.getASTContext ();
3848
+ ctx.Diags .diagnose (lastComp->getNameLoc (), diag::unknown_attribute,
3849
+ lastComp->getNameRef ().getBaseIdentifier ().str ());
3850
+
3851
+ return ErrorType::get (ctx);
3852
+ }
3853
+
3854
+ diagnoseUnboundGenericType (result,
3855
+ lastComp->getNameLoc ().getBaseNameLoc ());
3856
+ }
3857
+
3858
+ return ErrorType::get (result->getASTContext ());
3873
3859
}
3874
3860
3875
3861
if (auto moduleTy = result->getAs <ModuleType>()) {
@@ -3879,12 +3865,11 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3879
3865
// Otherwise, emit an error.
3880
3866
if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
3881
3867
auto moduleName = moduleTy->getModule ()->getName ();
3882
- diagnose (Components.back ()->getNameLoc (),
3883
- diag::cannot_find_type_in_scope, DeclNameRef (moduleName));
3884
- diagnose (Components.back ()->getNameLoc (),
3885
- diag::note_module_as_type, moduleName);
3868
+ diagnose (lastComp->getNameLoc (), diag::cannot_find_type_in_scope,
3869
+ DeclNameRef (moduleName));
3870
+ diagnose (lastComp->getNameLoc (), diag::note_module_as_type, moduleName);
3886
3871
}
3887
- Components. back () ->setInvalid ();
3872
+ lastComp ->setInvalid ();
3888
3873
return ErrorType::get (getASTContext ());
3889
3874
}
3890
3875
0 commit comments