Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ class SourceFile final : public FileUnit {
MissingImportForMemberDiagnostics[decl].push_back(loc);
}

/// Returns true if there is a pending missing import diagnostic for \p decl.
bool hasDelayedMissingImportForMemberDiagnostic(const ValueDecl *decl) const {
return MissingImportForMemberDiagnostics.contains(decl);
}

DelayedMissingImportForMemberDiags
takeDelayedMissingImportForMemberDiagnostics() {
DelayedMissingImportForMemberDiags diags;
Expand Down
13 changes: 8 additions & 5 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,

auto reason = where.getExportabilityReason();
auto DC = where.getDeclContext();
auto SF = DC->getParentSourceFile();
ASTContext &ctx = DC->getASTContext();
auto originKind = getDisallowedOriginKind(D, where, downgradeToWarning);

Expand Down Expand Up @@ -275,16 +276,18 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
if (originKind == DisallowedOriginKind::None)
return false;

auto diagName = D->getName();
// Some diagnostics emitted with the `MemberImportVisibility` feature enabled
// subsume these diagnostics.
if (originKind == DisallowedOriginKind::MissingImport &&
ctx.LangOpts.hasFeature(Feature::MemberImportVisibility) && SF &&
SF->hasDelayedMissingImportForMemberDiagnostic(D))
return false;

if (auto accessor = dyn_cast<AccessorDecl>(D)) {
// Only diagnose accessors if their disallowed origin kind differs from
// that of their storage.
if (getDisallowedOriginKind(accessor->getStorage(), where) == originKind)
return false;

// For accessors, diagnose with the name of the storage instead of the
// implicit '_'.
diagName = accessor->getStorage()->getName();
}

auto fragileKind = where.getFragileFunctionKind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ extension Int {
internal func usesTypealiasInInternalUsesOnly(x: TypealiasInInternalUsesOnly) {} // expected-error {{type alias 'TypealiasInInternalUsesOnly' is not available due to missing import of defining module 'InternalUsesOnly'}}
package func usesTypealiasInPackageUsesOnly(x: TypealiasInPackageUsesOnly) {} // expected-error {{type alias 'TypealiasInPackageUsesOnly' is not available due to missing import of defining module 'PackageUsesOnly'}}
public func usesTypealiasInPublicUsesOnly(x: TypealiasInPublicUsesOnly) {} // expected-error {{type alias 'TypealiasInPublicUsesOnly' is not available due to missing import of defining module 'PublicUsesOnly'}}
// expected-warning@-1 {{cannot use type alias 'TypealiasInPublicUsesOnly' here; 'PublicUsesOnly' was not imported by this file}}
public func usesTypealiasInMixedUses(x: TypealiasInMixedUses) {} // expected-error {{type alias 'TypealiasInMixedUses' is not available due to missing import of defining module 'MixedUses'}}
// expected-warning@-1 {{cannot use type alias 'TypealiasInMixedUses' here; 'MixedUses' was not imported by this file}}
internal func usesTypealiasInMixedUses_Internal(x: TypealiasInMixedUses) {} // expected-error {{type alias 'TypealiasInMixedUses' is not available due to missing import of defining module 'MixedUses'}}
}

Expand All @@ -78,9 +76,7 @@ private func usesTypealiasInInternalUsesOnly_Private(x: Int.TypealiasInInternalU
internal func usesTypealiasInInternalUsesOnly(x: Int.TypealiasInInternalUsesOnly) {} // expected-error {{type alias 'TypealiasInInternalUsesOnly' is not available due to missing import of defining module 'InternalUsesOnly'}}
package func usesTypealiasInPackageUsesOnly(x: Int.TypealiasInPackageUsesOnly) {} // expected-error {{type alias 'TypealiasInPackageUsesOnly' is not available due to missing import of defining module 'PackageUsesOnly'}}
public func usesTypealiasInPublicUsesOnly(x: Int.TypealiasInPublicUsesOnly) {} // expected-error {{type alias 'TypealiasInPublicUsesOnly' is not available due to missing import of defining module 'PublicUsesOnly'}}
// expected-warning@-1 {{cannot use type alias 'TypealiasInPublicUsesOnly' here; 'PublicUsesOnly' was not imported by this file}}
public func usesTypealiasInMixedUses(x: Int.TypealiasInMixedUses) {} // expected-error {{type alias 'TypealiasInMixedUses' is not available due to missing import of defining module 'MixedUses'}}
// expected-warning@-1 {{cannot use type alias 'TypealiasInMixedUses' here; 'MixedUses' was not imported by this file}}
internal func usesTypealiasInMixedUses_Internal(x: Int.TypealiasInMixedUses) {} // expected-error {{type alias 'TypealiasInMixedUses' is not available due to missing import of defining module 'MixedUses'}}

//--- extensions.swift
Expand All @@ -104,12 +100,10 @@ extension Int.NestedInPackageUsesOnly { // expected-error {{struct 'NestedInPack
}

extension Int.NestedInPublicUsesOnly { // expected-error {{struct 'NestedInPublicUsesOnly' is not available due to missing import of defining module 'PublicUsesOnly'}}
// expected-warning@-1 {{cannot use struct 'NestedInPublicUsesOnly' in an extension with public or '@usableFromInline' members; 'PublicUsesOnly' was not imported by this file}}
public func publicMethod() {}
}

extension Int.NestedInMixedUses { // expected-error {{struct 'NestedInMixedUses' is not available due to missing import of defining module 'MixedUses'}}
// expected-warning@-1 {{cannot use struct 'NestedInMixedUses' in an extension with public or '@usableFromInline' members; 'MixedUses' was not imported by this file}}
public func publicMethod() {}
}

Expand Down