Skip to content

Commit 4883013

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. (cherry picked from commit 1649b5e)
1 parent 08af019 commit 4883013

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

lib/Sema/TypeCheckAvailability.cpp

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

2310-
err.warnUntilSwiftVersion(6);
2311-
err.limitBehavior(behaviorLimitForExplicitUnavailability(rootConf, dc));
2310+
auto behaviorLimit = behaviorLimitForExplicitUnavailability(rootConf, dc);
2311+
if (behaviorLimit >= DiagnosticBehavior::Warning)
2312+
err.limitBehavior(behaviorLimit);
2313+
else
2314+
err.warnUntilSwiftVersion(6);
23122315

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

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4819,13 +4819,12 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
48194819
SourceFile *file = decl->getDeclContext()->getParentSourceFile();
48204820
bool inSwiftinterface =
48214821
file && file->Kind == SourceFileKind::Interface;
4822-
ctx.Diags.diagnose(
4823-
attr->getLocation(),
4824-
diag::unsafe_global_actor)
4825-
.fixItRemove(attr->getArgs()->getSourceRange())
4826-
.fixItInsert(attr->getLocation(), "@preconcurrency ")
4827-
.warnUntilSwiftVersion(6)
4828-
.limitBehaviorIf(inSwiftinterface, DiagnosticBehavior::Ignore);
4822+
if (!inSwiftinterface) {
4823+
ctx.Diags.diagnose(attr->getLocation(), diag::unsafe_global_actor)
4824+
.fixItRemove(attr->getArgs()->getSourceRange())
4825+
.fixItInsert(attr->getLocation(), "@preconcurrency ")
4826+
.warnUntilSwiftVersion(6);
4827+
}
48294828
} else {
48304829
ctx.Diags.diagnose(
48314830
attr->getLocation(),
@@ -6383,11 +6382,14 @@ static bool checkSendableInstanceStorage(
63836382
return true;
63846383
}
63856384

6386-
property->diagnose(diag::non_concurrent_type_member,
6387-
propertyType, false, property->getName(),
6388-
nominal)
6389-
.limitBehaviorUntilSwiftVersion(behavior, 6)
6390-
.limitBehaviorIf(preconcurrency);
6385+
if (preconcurrency)
6386+
behavior = preconcurrency.value();
6387+
6388+
property
6389+
->diagnose(diag::non_concurrent_type_member, propertyType,
6390+
false, property->getName(), nominal)
6391+
.limitBehaviorWithPreconcurrency(behavior,
6392+
preconcurrency.has_value());
63916393
return false;
63926394
});
63936395

@@ -6425,10 +6427,14 @@ static bool checkSendableInstanceStorage(
64256427
return true;
64266428
}
64276429

6428-
element->diagnose(diag::non_concurrent_type_member, type,
6429-
true, element->getName(), nominal)
6430-
.limitBehaviorUntilSwiftVersion(behavior, 6)
6431-
.limitBehaviorIf(preconcurrency);
6430+
if (preconcurrency)
6431+
behavior = preconcurrency.value();
6432+
6433+
element
6434+
->diagnose(diag::non_concurrent_type_member, type, true,
6435+
element->getName(), nominal)
6436+
.limitBehaviorWithPreconcurrency(behavior,
6437+
preconcurrency.has_value());
64326438
return false;
64336439
});
64346440

0 commit comments

Comments
 (0)