Skip to content

Commit 484847e

Browse files
authored
Merge pull request #63278 from tshortli/avoid-diagnosing-missing-import-for-desugared-typealias-in-non-resilient-modules
Sema: Avoid diagnosing missing imports for desugared typealiases in non-resilient modules
2 parents 3fd895a + d4abf8f commit 484847e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,19 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
121121
if (originKind == DisallowedOriginKind::None)
122122
return false;
123123

124+
auto exportingModule = where.getDeclContext()->getParentModule();
125+
ASTContext &ctx = exportingModule->getASTContext();
126+
127+
// As an exception, if the import of the module that defines the desugared
128+
// decl is just missing (as opposed to imported explicitly with reduced
129+
// visibility) then we should only diagnose if we're building a resilient
130+
// module.
131+
if (originKind == DisallowedOriginKind::MissingImport &&
132+
!exportingModule->isResilient())
133+
return false;
134+
124135
auto definingModule = D->getModuleContext();
125-
ASTContext &ctx = definingModule->getASTContext();
126136
auto fragileKind = where.getFragileFunctionKind();
127-
128137
if (fragileKind.kind == FragileFunctionKind::None) {
129138
auto reason = where.getExportabilityReason();
130139
ctx.Diags

test/Sema/missing-import-typealias-swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// RUN: %target-swift-emit-module-interface(%t/Aliases.swiftinterface) %t/Aliases.swift -I %t
88
// RUN: %target-swift-typecheck-module-from-interface(%t/Aliases.swiftinterface) -I %t
99

10-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -I %t -swift-version 6
10+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -enable-library-evolution -I %t -swift-version 6
1111

1212
// REQUIRES: asserts
1313

14-
// This test is a simplified version of implicit-import-typealias.swift that
14+
// This test is a simplified version of missing-import-typealias.swift that
1515
// verifies errors are emitted instead of warnings in Swift 6.
1616

1717
//--- Original.swift

test/Sema/missing-import-typealias.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
// RUN: %target-swift-emit-module-interface(%t/Aliases.swiftinterface) %t/Aliases.swift -I %t
88
// RUN: %target-swift-typecheck-module-from-interface(%t/Aliases.swiftinterface) -I %t
99

10-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -I %t
11-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesImplementationOnlyImport.swift -I %t
12-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesSPIOnlyImport.swift -I %t -experimental-spi-only-imports
13-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesWithImport.swift -I %t
10+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -enable-library-evolution -I %t
11+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesImplementationOnlyImport.swift -enable-library-evolution -I %t
12+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesSPIOnlyImport.swift -enable-library-evolution -I %t -experimental-spi-only-imports
13+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesWithImport.swift -enable-library-evolution -I %t
14+
15+
/// With library evolution disabled UsesAliasesNoImport.swift should compile without diagnostics.
16+
// RUN: %target-swift-frontend -typecheck %t/UsesAliasesNoImport.swift -I %t | %FileCheck %t/UsesAliasesNoImport.swift --check-prefix=CHECK-NON-RESILIENT --allow-empty
1417

1518
/// The swiftinterface is broken by the missing import without the workaround.
1619
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImport.swiftinterface) %t/UsesAliasesNoImport.swift -I %t \
@@ -61,6 +64,8 @@ public typealias WrapperAlias = Wrapper
6164

6265
import Aliases
6366

67+
// CHECK-NON-RESILIENT-NOT: was not imported by this file
68+
6469
// expected-warning@+2 {{'ClazzAlias' aliases 'Original.Clazz' and cannot be used here because 'Original' was not imported by this file; this is an error in Swift 6}}
6570
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
6671
public class InheritsFromClazzAlias: ClazzAlias {}

0 commit comments

Comments
 (0)