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