Skip to content

Commit 1649b5e

Browse files
committed
[Concurrency] Avoid dowgrading diagnostics multiple times
Unify `warn` + `limitBehavior` into a single call to make sure that diagnostic doesn't get downgraded multiple times because that could affect how diagnostics are tracked.
1 parent 7c258f2 commit 1649b5e

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,8 +2337,11 @@ diagnosePotentialUnavailability(const RootProtocolConformance *rootConf,
23372337
ctx.getTargetPlatformStringForDiagnostics(),
23382338
availability.getRawMinimumVersion());
23392339

2340-
err.warnUntilSwiftVersion(6);
2341-
err.limitBehavior(behaviorLimitForExplicitUnavailability(rootConf, dc));
2340+
auto behaviorLimit = behaviorLimitForExplicitUnavailability(rootConf, dc);
2341+
if (behaviorLimit >= DiagnosticBehavior::Warning)
2342+
err.limitBehavior(behaviorLimit);
2343+
else
2344+
err.warnUntilSwiftVersion(6);
23422345

23432346
// Direct a fixit to the error if an existing guard is nearly-correct
23442347
if (fixAvailabilityByNarrowingNearbyVersionCheck(loc, dc, availability, ctx,

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,14 +4853,12 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
48534853
bool isUnsafe = attr->isArgUnsafe();
48544854
if (attr->hasArgs()) {
48554855
if (isUnsafe) {
4856-
bool inSwiftinterface = decl->getDeclContext()->isInSwiftinterface();
4857-
ctx.Diags.diagnose(
4858-
attr->getLocation(),
4859-
diag::unsafe_global_actor)
4860-
.fixItRemove(attr->getArgs()->getSourceRange())
4861-
.fixItInsert(attr->getLocation(), "@preconcurrency ")
4862-
.warnUntilSwiftVersion(6)
4863-
.limitBehaviorIf(inSwiftinterface, DiagnosticBehavior::Ignore);
4856+
if (!decl->getDeclContext()->isInSwiftinterface()) {
4857+
ctx.Diags.diagnose(attr->getLocation(), diag::unsafe_global_actor)
4858+
.fixItRemove(attr->getArgs()->getSourceRange())
4859+
.fixItInsert(attr->getLocation(), "@preconcurrency ")
4860+
.warnUntilSwiftVersion(6);
4861+
}
48644862
} else {
48654863
ctx.Diags.diagnose(
48664864
attr->getLocation(),
@@ -6490,11 +6488,14 @@ static bool checkSendableInstanceStorage(
64906488
return true;
64916489
}
64926490

6493-
property->diagnose(diag::non_concurrent_type_member,
6494-
propertyType, false, property->getName(),
6495-
nominal)
6496-
.limitBehaviorUntilSwiftVersion(behavior, 6)
6497-
.limitBehaviorIf(preconcurrency);
6491+
if (preconcurrency)
6492+
behavior = preconcurrency.value();
6493+
6494+
property
6495+
->diagnose(diag::non_concurrent_type_member, propertyType,
6496+
false, property->getName(), nominal)
6497+
.limitBehaviorWithPreconcurrency(behavior,
6498+
preconcurrency.has_value());
64986499
return false;
64996500
});
65006501

@@ -6532,10 +6533,14 @@ static bool checkSendableInstanceStorage(
65326533
return true;
65336534
}
65346535

6535-
element->diagnose(diag::non_concurrent_type_member, type,
6536-
true, element->getName(), nominal)
6537-
.limitBehaviorUntilSwiftVersion(behavior, 6)
6538-
.limitBehaviorIf(preconcurrency);
6536+
if (preconcurrency)
6537+
behavior = preconcurrency.value();
6538+
6539+
element
6540+
->diagnose(diag::non_concurrent_type_member, type, true,
6541+
element->getName(), nominal)
6542+
.limitBehaviorWithPreconcurrency(behavior,
6543+
preconcurrency.has_value());
65396544
return false;
65406545
});
65416546

0 commit comments

Comments
 (0)