@@ -1632,60 +1632,6 @@ static Type applyNonEscapingFromContext(DeclContext *DC,
1632
1632
return ty;
1633
1633
}
1634
1634
1635
- // / Returns a valid type or ErrorType in case of an error.
1636
- Type TypeChecker::resolveIdentifierType (TypeResolution resolution,
1637
- IdentTypeRepr *IdType) {
1638
- const auto options = resolution.getOptions ();
1639
- auto DC = resolution.getDeclContext ();
1640
- ASTContext &ctx = DC->getASTContext ();
1641
- auto &diags = ctx.Diags ;
1642
- auto ComponentRange = IdType->getComponentRange ();
1643
- auto Components = llvm::makeArrayRef (ComponentRange.begin (),
1644
- ComponentRange.end ());
1645
- Type result = resolveIdentTypeComponent (resolution, Components);
1646
- if (!result) return nullptr ;
1647
-
1648
- if (auto moduleTy = result->getAs <ModuleType>()) {
1649
- // Allow module types only if flag is specified.
1650
- if (options.contains (TypeResolutionFlags::AllowModule))
1651
- return moduleTy;
1652
- // Otherwise, emit an error.
1653
- if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
1654
- auto moduleName = moduleTy->getModule ()->getName ();
1655
- diags.diagnose (Components.back ()->getNameLoc (),
1656
- diag::cannot_find_type_in_scope, DeclNameRef (moduleName));
1657
- diags.diagnose (Components.back ()->getNameLoc (),
1658
- diag::note_module_as_type, moduleName);
1659
- }
1660
- Components.back ()->setInvalid ();
1661
- return ErrorType::get (ctx);
1662
- }
1663
-
1664
- // Hack to apply context-specific @escaping to a typealias with an underlying
1665
- // function type.
1666
- if (result->is <FunctionType>())
1667
- result = applyNonEscapingFromContext (DC, result, options);
1668
-
1669
- // Check the availability of the type.
1670
-
1671
- // We allow a type to conform to a protocol that is less available than
1672
- // the type itself. This enables a type to retroactively model or directly
1673
- // conform to a protocol only available on newer OSes and yet still be used on
1674
- // older OSes.
1675
- // To support this, inside inheritance clauses we allow references to
1676
- // protocols that are unavailable in the current type refinement context.
1677
-
1678
- if (!options.contains (TypeResolutionFlags::SilenceErrors) &&
1679
- !options.contains (TypeResolutionFlags::AllowUnavailable) &&
1680
- diagnoseAvailability (IdType, DC,
1681
- options.contains (TypeResolutionFlags::AllowUnavailableProtocol))) {
1682
- Components.back ()->setInvalid ();
1683
- return ErrorType::get (ctx);
1684
- }
1685
-
1686
- return result;
1687
- }
1688
-
1689
1635
// / Validate whether type associated with @autoclosure attribute is correct,
1690
1636
// / it supposed to be a function type with no parameters.
1691
1637
// / \returns true if there was an error, false otherwise.
@@ -1831,6 +1777,8 @@ namespace {
1831
1777
SmallVectorImpl<SILYieldInfo> &yields,
1832
1778
SmallVectorImpl<SILResultInfo> &results,
1833
1779
Optional<SILResultInfo> &errorResult);
1780
+ Type resolveIdentifierType (IdentTypeRepr *IdType,
1781
+ TypeResolutionOptions options);
1834
1782
Type resolveSpecifierTypeRepr (SpecifierTypeRepr *repr,
1835
1783
TypeResolutionOptions options);
1836
1784
Type resolveArrayType (ArrayTypeRepr *repr,
@@ -1949,8 +1897,7 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
1949
1897
case TypeReprKind::SimpleIdent:
1950
1898
case TypeReprKind::GenericIdent:
1951
1899
case TypeReprKind::CompoundIdent:
1952
- return TypeChecker::resolveIdentifierType (resolution.withOptions (options),
1953
- cast<IdentTypeRepr>(repr));
1900
+ return resolveIdentifierType (cast<IdentTypeRepr>(repr), options);
1954
1901
1955
1902
case TypeReprKind::Function: {
1956
1903
if (!(options & TypeResolutionFlags::SILType)) {
@@ -3258,6 +3205,56 @@ bool TypeResolver::resolveSILResults(TypeRepr *repr,
3258
3205
yields, ordinaryResults, errorResult);
3259
3206
}
3260
3207
3208
+ Type TypeResolver::resolveIdentifierType (IdentTypeRepr *IdType,
3209
+ TypeResolutionOptions options) {
3210
+ auto ComponentRange = IdType->getComponentRange ();
3211
+ auto Components = llvm::makeArrayRef (ComponentRange.begin (),
3212
+ ComponentRange.end ());
3213
+ Type result = resolveIdentTypeComponent (resolution.withOptions (options),
3214
+ Components);
3215
+ if (!result) return nullptr ;
3216
+
3217
+ if (auto moduleTy = result->getAs <ModuleType>()) {
3218
+ // Allow module types only if flag is specified.
3219
+ if (options.contains (TypeResolutionFlags::AllowModule))
3220
+ return moduleTy;
3221
+ // Otherwise, emit an error.
3222
+ if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
3223
+ auto moduleName = moduleTy->getModule ()->getName ();
3224
+ diagnose (Components.back ()->getNameLoc (),
3225
+ diag::cannot_find_type_in_scope, DeclNameRef (moduleName));
3226
+ diagnose (Components.back ()->getNameLoc (),
3227
+ diag::note_module_as_type, moduleName);
3228
+ }
3229
+ Components.back ()->setInvalid ();
3230
+ return ErrorType::get (Context);
3231
+ }
3232
+
3233
+ // Hack to apply context-specific @escaping to a typealias with an underlying
3234
+ // function type.
3235
+ if (result->is <FunctionType>())
3236
+ result = applyNonEscapingFromContext (DC, result, options);
3237
+
3238
+ // Check the availability of the type.
3239
+
3240
+ // We allow a type to conform to a protocol that is less available than
3241
+ // the type itself. This enables a type to retroactively model or directly
3242
+ // conform to a protocol only available on newer OSes and yet still be used on
3243
+ // older OSes.
3244
+ // To support this, inside inheritance clauses we allow references to
3245
+ // protocols that are unavailable in the current type refinement context.
3246
+
3247
+ if (!options.contains (TypeResolutionFlags::SilenceErrors) &&
3248
+ !options.contains (TypeResolutionFlags::AllowUnavailable) &&
3249
+ diagnoseAvailability (IdType, DC,
3250
+ options.contains (TypeResolutionFlags::AllowUnavailableProtocol))) {
3251
+ Components.back ()->setInvalid ();
3252
+ return ErrorType::get (Context);
3253
+ }
3254
+
3255
+ return result;
3256
+ }
3257
+
3261
3258
Type TypeResolver::resolveSpecifierTypeRepr (SpecifierTypeRepr *repr,
3262
3259
TypeResolutionOptions options) {
3263
3260
// inout is only valid for (non-Subscript and non-EnumCaseDecl)
0 commit comments