Skip to content

Commit 3963122

Browse files
committed
[MiscDiagnostics] Make sure that diagnostics look through function conversions
None of the diagnostics in MiscDiagnostics make a distinction between sendable or actor-isolated function references which means that we can skip conversions while reaching for a declaration used in an application. (cherry picked from commit 64a200a)
1 parent 00b223f commit 3963122

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
257257
// Void to _ then warn, because that is redundant.
258258
if (auto DAE = dyn_cast<DiscardAssignmentExpr>(destExpr)) {
259259
if (auto CE = dyn_cast<CallExpr>(AE->getSrc())) {
260-
if (isa_and_nonnull<FuncDecl>(CE->getCalledValue()) &&
260+
if (getAsDecl<FuncDecl>(
261+
CE->getCalledValue(/*skipFunctionConversions=*/true)) &&
261262
CE->getType()->isVoid()) {
262263
Ctx.Diags
263264
.diagnose(DAE->getLoc(),
@@ -311,7 +312,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
311312
// FIXME: Duplicate labels on enum payloads should be diagnosed
312313
// when declared, not when called.
313314
if (auto *CE = dyn_cast_or_null<CallExpr>(E)) {
314-
auto calledValue = CE->getCalledValue();
315+
auto calledValue = CE->getCalledValue(/*skipFunctionConversions=*/true);
315316
if (calledValue && isa<EnumElementDecl>(calledValue)) {
316317
auto *args = CE->getArgs();
317318
SmallVector<Identifier, 4> scratch;
@@ -1464,6 +1465,9 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
14641465
if (auto dotSyntax = dyn_cast<DotSyntaxCallExpr>(fnExpr))
14651466
fnExpr = dotSyntax->getSemanticFn();
14661467

1468+
if (auto *FCE = dyn_cast<FunctionConversionExpr>(fnExpr))
1469+
fnExpr = FCE->getSubExpr();
1470+
14671471
auto DRE = dyn_cast<DeclRefExpr>(fnExpr);
14681472
if (!DRE || !DRE->getDecl()->isOperator())
14691473
return;
@@ -5093,7 +5097,7 @@ static void diagnoseUnintendedOptionalBehavior(const Expr *E,
50935097
return declRef->getDecl();
50945098

50955099
if (auto *apply = dyn_cast<ApplyExpr>(E)) {
5096-
auto *decl = apply->getCalledValue();
5100+
auto *decl = apply->getCalledValue(/*skipFunctionConversions=*/true);
50975101
if (isa_and_nonnull<AbstractFunctionDecl>(decl))
50985102
return decl;
50995103
}
@@ -5232,9 +5236,10 @@ static void diagnoseUnintendedOptionalBehavior(const Expr *E,
52325236

52335237
void diagnoseIfUnintendedInterpolation(CallExpr *segment,
52345238
UnintendedInterpolationKind kind) {
5235-
if (interpolationWouldBeUnintended(segment->getCalledValue(), kind))
5239+
if (interpolationWouldBeUnintended(
5240+
segment->getCalledValue(/*skipFunctionConversions=*/true), kind))
52365241
if (auto firstArg =
5237-
getFirstArgIfUnintendedInterpolation(segment->getArgs(), kind))
5242+
getFirstArgIfUnintendedInterpolation(segment->getArgs(), kind))
52385243
diagnoseUnintendedInterpolation(firstArg, kind);
52395244
}
52405245

@@ -5445,7 +5450,7 @@ static void maybeDiagnoseCallToKeyValueObserveMethod(const Expr *E,
54455450
KVOObserveCallWalker(ASTContext &ctx) : C(ctx) {}
54465451

54475452
void maybeDiagnoseCallExpr(CallExpr *expr) {
5448-
auto fn = expr->getCalledValue();
5453+
auto fn = expr->getCalledValue(/*skipFunctionConversions=*/true);
54495454
if (!fn)
54505455
return;
54515456
SmallVector<KeyPathExpr *, 1> keyPathArgs;
@@ -5583,9 +5588,10 @@ static void diagnoseComparisonWithNaN(const Expr *E, const DeclContext *DC) {
55835588
// Dig out the function declaration.
55845589
if (auto Fn = BE->getFn()) {
55855590
if (auto DSCE = dyn_cast<DotSyntaxCallExpr>(Fn)) {
5586-
comparisonDecl = DSCE->getCalledValue();
5591+
comparisonDecl =
5592+
DSCE->getCalledValue(/*skipFunctionConversions=*/true);
55875593
} else {
5588-
comparisonDecl = BE->getCalledValue();
5594+
comparisonDecl = BE->getCalledValue(/*skipFunctionConversions=*/true);
55895595
}
55905596
}
55915597

0 commit comments

Comments
 (0)