Skip to content

Commit baa9d71

Browse files
committed
Sema: Pull conformance exportability checking out of resolveType()
1 parent 94e999a commit baa9d71

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,8 +2071,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
20712071

20722072
// Check the type for references to unavailable conformances.
20732073
if (type)
2074-
if (!context->getDeclContext()->isLocalContext())
2075-
diagnoseTypeAvailability(type, context->getLoc(), DC);
2074+
diagnoseTypeAvailability(type, context->getLoc(), DC);
20762075
}
20772076

20782077
void checkGenericParams(const GenericContext *ownerCtx,

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,20 @@ class AvailabilityWalker : public ASTWalker {
24582458
walkInOutExpr(IO);
24592459
return skipChildren();
24602460
}
2461+
if (auto T = dyn_cast<TypeExpr>(E)) {
2462+
if (!T->isImplicit())
2463+
if (auto type = T->getType())
2464+
diagnoseTypeAvailability(type, E->getLoc(), DC);
2465+
}
2466+
if (auto CE = dyn_cast<ClosureExpr>(E)) {
2467+
for (auto *param : *CE->getParameters()) {
2468+
diagnoseTypeAvailability(param->getInterfaceType(), E->getLoc(), DC);
2469+
}
2470+
diagnoseTypeAvailability(CE->getResultType(), E->getLoc(), DC);
2471+
}
2472+
if (auto IE = dyn_cast<IsExpr>(E)) {
2473+
diagnoseTypeAvailability(IE->getCastType(), E->getLoc(), DC);
2474+
}
24612475

24622476
return visitChildren();
24632477
}
@@ -2894,6 +2908,14 @@ class StmtAvailabilityWalker : public ASTWalker {
28942908
diagnoseTypeReprAvailability(T, DC);
28952909
return false;
28962910
}
2911+
2912+
std::pair<bool, Pattern *> walkToPatternPre(Pattern *P) override {
2913+
if (auto *IP = dyn_cast<IsPattern>(P))
2914+
if (auto T = IP->getCastType())
2915+
diagnoseTypeAvailability(T, P->getLoc(), DC);
2916+
2917+
return std::make_pair(true, P);
2918+
}
28972919
};
28982920

28992921
}

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,6 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
813813
const auto result = TypeChecker::applyUnboundGenericArguments(
814814
decl, unboundType->getParent(), loc, resolution, args);
815815

816-
const auto genericOptions = genericResolution.getOptions();
817-
if (!genericOptions.contains(TypeResolutionFlags::AllowUnavailable)) {
818-
if (genericOptions.isAnyExpr() || dc->getParent()->isLocalContext())
819-
if (dc->getResilienceExpansion() == ResilienceExpansion::Minimal)
820-
TypeChecker::diagnoseGenericTypeExportability(loc, result, dc);
821-
}
822-
823816
// Migration hack.
824817
bool isMutablePointer;
825818
if (isPointerToVoid(dc->getASTContext(), result, isMutablePointer)) {

test/Sema/implementation-only-import-inlinable-conformances.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct NormalProtoAssocHolder<T: NormalProto> {
3333
_ = x
3434
// FIXME: We get this error twice: once for the TypeExpr and once for the implicit init.
3535
_ = NormalProtoAssocHolder<NormalStruct>() // expected-error 2 {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
36-
_ = NormalProtoAssocHolder(nil as NormalStruct?) // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
36+
_ = NormalProtoAssocHolder(nil as NormalStruct?) // expected-error 2{{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
3737
}
3838

3939
func internalConformanceInBoundGeneric() {

test/Sema/spi-inlinable-conformances.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public struct NormalProtoAssocHolder<T: NormalProto> {
6767
_ = x
6868
// FIXME: We get this error twice: once for the TypeExpr and once for the implicit init.
6969
_ = NormalProtoAssocHolder<NormalStruct>() // expected-error 2 {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; the conformance is declared as SPI}}
70-
_ = NormalProtoAssocHolder(nil as NormalStruct?) // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; the conformance is declared as SPI}}
70+
_ = NormalProtoAssocHolder(nil as NormalStruct?) // expected-error 2{{cannot use conformance of 'NormalStruct' to 'NormalProto' here; the conformance is declared as SPI}}
7171
}
7272

7373
@_spi(AcceptInSPI)

0 commit comments

Comments
 (0)