@@ -194,7 +194,8 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
194194 auto ignoredDowngradeToWarning = DowngradeToWarning::No;
195195 auto originKind =
196196 getDisallowedOriginKind (D, where, ignoredDowngradeToWarning);
197- if (where.canReferenceOrigin (originKind))
197+ auto commonBehavior = where.behaviorForReferenceToOrigin (originKind);
198+ if (commonBehavior == DiagnosticBehavior::Ignore)
198199 return false ;
199200
200201 // As an exception, if the import of the module that defines the desugared
@@ -216,15 +217,17 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
216217 TAD, definingModule->getNameStr (), D->getNameStr (),
217218 static_cast <unsigned >(*reason), definingModule->getName (),
218219 static_cast <unsigned >(originKind))
219- .warnUntilLanguageModeIf (warnPreSwift6, 6 );
220+ .warnUntilLanguageModeIf (warnPreSwift6, 6 )
221+ .limitBehaviorIfMorePermissive (commonBehavior);
220222 } else {
221223 ctx.Diags
222224 .diagnose (loc,
223225 diag::inlinable_typealias_desugars_to_type_from_hidden_module,
224226 TAD, definingModule->getNameStr (), D->getNameStr (),
225227 fragileKind.getSelector (), definingModule->getName (),
226228 static_cast <unsigned >(originKind))
227- .warnUntilLanguageModeIf (warnPreSwift6, 6 );
229+ .warnUntilLanguageModeIf (warnPreSwift6, 6 )
230+ .limitBehaviorIfMorePermissive (commonBehavior);
228231 }
229232 D->diagnose (diag::kind_declared_here, DescriptiveDeclKind::Type);
230233
@@ -269,7 +272,13 @@ static bool shouldDiagnoseDeclAccess(const ValueDecl *D,
269272 switch (*reason) {
270273 case ExportabilityReason::ExtensionWithPublicMembers:
271274 case ExportabilityReason::ExtensionWithConditionalConformances:
272- return true ;
275+ // Allow public members in extensions of implicitly exported types.
276+ // Extensions cannot define stored variables avoiding the memory layout
277+ // concerns and we don't print swiftinterfaces in non-library-evolution
278+ // mode.
279+ // We should be able to always allow this if it's correctly guarded
280+ // at generating module interfaces and generated headers.
281+ return where.getExportedLevel () == ExportedLevel::Exported;
273282 case ExportabilityReason::Inheritance:
274283 case ExportabilityReason::ImplicitlyPublicInheritance:
275284 return isa<ProtocolDecl>(D);
@@ -323,7 +332,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
323332 }
324333 });
325334
326- if (where.canReferenceOrigin (originKind))
335+ auto commonBehavior = where.behaviorForReferenceToOrigin (originKind);
336+ if (commonBehavior == DiagnosticBehavior::Ignore)
327337 return false ;
328338
329339 auto fragileKind = where.getFragileFunctionKind ();
@@ -384,21 +394,16 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
384394 static_cast <unsigned >(*reason),
385395 definingModule->getName (),
386396 static_cast <unsigned >(originKind))
387- .limitBehavior (limit);
397+ .limitBehavior (limit. merge (commonBehavior) );
388398
389399 D->diagnose (diag::kind_declared_here, D->getDescriptiveKind ());
390400 } else {
391- // Only implicitly imported decls should be reported as a warning,
392- // and only for language versions below Swift 6.
393- assert (downgradeToWarning == DowngradeToWarning::No ||
394- originKind == DisallowedOriginKind::MissingImport &&
395- " Only implicitly imported decls should be reported as a warning." );
396-
397401 ctx.Diags .diagnose (loc, diag::inlinable_decl_ref_from_hidden_module, D,
398402 fragileKind.getSelector (), definingModule->getName (),
399403 static_cast <unsigned >(originKind))
400404 .warnUntilLanguageModeIf (downgradeToWarning == DowngradeToWarning::Yes,
401- 6 );
405+ 6 )
406+ .limitBehaviorIfMorePermissive (commonBehavior);
402407
403408 if (originKind == DisallowedOriginKind::MissingImport &&
404409 downgradeToWarning == DowngradeToWarning::Yes)
@@ -470,7 +475,8 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
470475 });
471476
472477 auto originKind = getDisallowedOriginKind (ext, where);
473- if (where.canReferenceOrigin (originKind))
478+ auto commonBehavior = where.behaviorForReferenceToOrigin (originKind);
479+ if (commonBehavior == DiagnosticBehavior::Ignore)
474480 return false ;
475481
476482 auto reason = where.getExportabilityReason ();
@@ -486,8 +492,9 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
486492 (warnIfConformanceUnavailablePreSwift6 &&
487493 originKind != DisallowedOriginKind::SPIOnly &&
488494 originKind != DisallowedOriginKind::NonPublicImport) ||
489- originKind == DisallowedOriginKind::MissingImport,
490- 6 );
495+ originKind == DisallowedOriginKind::MissingImport,
496+ 6 )
497+ .limitBehaviorIfMorePermissive (commonBehavior);
491498
492499 if (!ctx.LangOpts .hasFeature (Feature::StrictAccessControl) &&
493500 originKind == DisallowedOriginKind::MissingImport &&
0 commit comments