@@ -1632,60 +1632,6 @@ static Type applyNonEscapingFromContext(DeclContext *DC,
16321632 return ty;
16331633}
16341634
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-
16891635// / Validate whether type associated with @autoclosure attribute is correct,
16901636// / it supposed to be a function type with no parameters.
16911637// / \returns true if there was an error, false otherwise.
@@ -1831,6 +1777,8 @@ namespace {
18311777 SmallVectorImpl<SILYieldInfo> &yields,
18321778 SmallVectorImpl<SILResultInfo> &results,
18331779 Optional<SILResultInfo> &errorResult);
1780+ Type resolveIdentifierType (IdentTypeRepr *IdType,
1781+ TypeResolutionOptions options);
18341782 Type resolveSpecifierTypeRepr (SpecifierTypeRepr *repr,
18351783 TypeResolutionOptions options);
18361784 Type resolveArrayType (ArrayTypeRepr *repr,
@@ -1949,8 +1897,7 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
19491897 case TypeReprKind::SimpleIdent:
19501898 case TypeReprKind::GenericIdent:
19511899 case TypeReprKind::CompoundIdent:
1952- return TypeChecker::resolveIdentifierType (resolution.withOptions (options),
1953- cast<IdentTypeRepr>(repr));
1900+ return resolveIdentifierType (cast<IdentTypeRepr>(repr), options);
19541901
19551902 case TypeReprKind::Function: {
19561903 if (!(options & TypeResolutionFlags::SILType)) {
@@ -3258,6 +3205,56 @@ bool TypeResolver::resolveSILResults(TypeRepr *repr,
32583205 yields, ordinaryResults, errorResult);
32593206}
32603207
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+
32613258Type TypeResolver::resolveSpecifierTypeRepr (SpecifierTypeRepr *repr,
32623259 TypeResolutionOptions options) {
32633260 // inout is only valid for (non-Subscript and non-EnumCaseDecl)
0 commit comments