@@ -730,6 +730,12 @@ Type TypeChecker::applyGenericArguments(Type type,
730
730
if (!result)
731
731
return result;
732
732
733
+ if (!options.contains (TypeResolutionFlags::AllowUnavailable)) {
734
+ if (options.isAnyExpr () || dc->getParent ()->isLocalContext ())
735
+ if (dc->getResilienceExpansion () == ResilienceExpansion::Minimal)
736
+ diagnoseGenericTypeExportability (loc, result, dc);
737
+ }
738
+
733
739
// Migration hack.
734
740
bool isMutablePointer;
735
741
if (isPointerToVoid (dc->getASTContext (), result, isMutablePointer)) {
@@ -1657,10 +1663,9 @@ static bool validateAutoClosureAttr(DiagnosticEngine &Diags, const SourceLoc &lo
1657
1663
// / has `@autoclosure` attribute, and if so, validate that such use is correct.
1658
1664
// / \returns true if there was an error, false otherwise.
1659
1665
static bool validateAutoClosureAttributeUse (DiagnosticEngine &Diags,
1660
- const TypeLoc &loc ,
1666
+ const TypeRepr *TR ,
1661
1667
Type type,
1662
1668
TypeResolutionOptions options) {
1663
- auto *TR = loc.getTypeRepr ();
1664
1669
if (!TR || TR->isInvalid ())
1665
1670
return false ;
1666
1671
@@ -1683,7 +1688,7 @@ static bool validateAutoClosureAttributeUse(DiagnosticEngine &Diags,
1683
1688
isValid &= llvm::none_of (
1684
1689
fnType->getParams (), [&](const FunctionType::Param ¶m) {
1685
1690
return param.isAutoClosure () &&
1686
- validateAutoClosureAttr (Diags, loc. getLoc (),
1691
+ validateAutoClosureAttr (Diags, TR-> getLoc (),
1687
1692
param.getPlainType ());
1688
1693
});
1689
1694
}
@@ -1702,30 +1707,8 @@ bool TypeChecker::validateType(ASTContext &Context, TypeLoc &Loc,
1702
1707
if (Context.Stats )
1703
1708
Context.Stats ->getFrontendCounters ().NumTypesValidated ++;
1704
1709
1705
- Type type = Loc.getType ();
1706
- if (type.isNull ()) {
1707
- type = resolution.resolveType (Loc.getTypeRepr (), options);
1708
- if (!type) {
1709
- type = ErrorType::get (Context);
1710
- // Diagnose types that are illegal in SIL.
1711
- } else if (options.contains (TypeResolutionFlags::SILType)
1712
- && !type->isLegalSILType ()) {
1713
- Context.Diags .diagnose (Loc.getLoc (), diag::illegal_sil_type, type);
1714
- Loc.setInvalidType (Context);
1715
- return true ;
1716
- } else if (validateAutoClosureAttributeUse (Context.Diags , Loc,
1717
- type, options)) {
1718
- type = ErrorType::get (Context);
1719
- }
1720
- }
1721
-
1710
+ Type type = resolution.resolveType (Loc.getTypeRepr (), options);
1722
1711
Loc.setType (type);
1723
- if (!type->hasError ()) {
1724
- const DeclContext *DC = resolution.getDeclContext ();
1725
- if (options.isAnyExpr () || DC->getParent ()->isLocalContext ())
1726
- if (DC->getResilienceExpansion () == ResilienceExpansion::Minimal)
1727
- TypeChecker::diagnoseGenericTypeExportability (Loc, DC);
1728
- }
1729
1712
1730
1713
return type->hasError ();
1731
1714
}
@@ -1828,16 +1811,34 @@ namespace {
1828
1811
1829
1812
Type TypeResolution::resolveType (TypeRepr *TyR,
1830
1813
TypeResolutionOptions options) {
1831
- FrontendStatsTracer StatsTracer (getASTContext ().Stats , " resolve-type" , TyR);
1832
- PrettyStackTraceTypeRepr stackTrace (getASTContext (), " resolving" , TyR);
1814
+ auto &ctx = getASTContext ();
1815
+
1816
+ FrontendStatsTracer StatsTracer (ctx.Stats , " resolve-type" , TyR);
1817
+ PrettyStackTraceTypeRepr stackTrace (ctx, " resolving" , TyR);
1833
1818
1834
1819
TypeResolver typeResolver (*this );
1835
1820
auto result = typeResolver.resolveType (TyR, options);
1836
-
1837
- // If we resolved down to an error, make sure to mark the typeRepr as invalid
1838
- // so we don't produce a redundant diagnostic.
1839
- if (result && result->hasError ())
1840
- TyR->setInvalid ();
1821
+
1822
+ if (result) {
1823
+ // If we resolved down to an error, make sure to mark the typeRepr as invalid
1824
+ // so we don't produce a redundant diagnostic.
1825
+ if (result->hasError ()) {
1826
+ TyR->setInvalid ();
1827
+ return result;
1828
+ }
1829
+
1830
+ auto loc = TyR->getLoc ();
1831
+
1832
+ if (options.contains (TypeResolutionFlags::SILType)
1833
+ && !result->isLegalSILType ()) {
1834
+ ctx.Diags .diagnose (loc, diag::illegal_sil_type, result);
1835
+ return ErrorType::get (ctx);
1836
+ }
1837
+
1838
+ if (validateAutoClosureAttributeUse (ctx.Diags , TyR, result, options))
1839
+ return ErrorType::get (ctx);
1840
+ }
1841
+
1841
1842
return result;
1842
1843
}
1843
1844
0 commit comments