Skip to content

Commit dcf75de

Browse files
committed
[#16431][Amendments] Note emitting amendment & use generic note
Show the note always if there is a single candidate Switch to using the generic 'declared here' diag introduced in #16766
1 parent 025f4dd commit dcf75de

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ ERROR(could_not_find_subscript_member_did_you_mean,none,
8484
"value of type %0 has no property or method named 'subscript'; "
8585
"did you mean to use the subscript operator?",
8686
(Type))
87-
NOTE(subscript_declared_here,none,
88-
"declared here", ())
8987

9088
ERROR(could_not_find_enum_case,none,
9189
"enum type %0 has no case %1; did you mean %2", (Type, DeclName, DeclName))

lib/Sema/CSDiag.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5546,9 +5546,16 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
55465546
baseType);
55475547
diag.highlight(memberRange).highlight(nameLoc.getSourceRange());
55485548

5549-
if (candidateInfo.closeness != CC_ExactMatch)
5549+
auto showNote = [&]() {
5550+
diag.flush();
5551+
if (candidateInfo.size() == 1)
5552+
diagnose(candidateInfo.candidates.front().getDecl(),
5553+
diag::kind_declared_here, DescriptiveDeclKind::Subscript);
5554+
};
5555+
if (candidateInfo.closeness != CC_ExactMatch) {
5556+
showNote();
55505557
return true;
5551-
5558+
}
55525559
auto toCharSourceRange = Lexer::getCharSourceRangeFromSourceRange;
55535560
auto lastArgSymbol = toCharSourceRange(CS.TC.Context.SourceMgr,
55545561
argExpr->getEndLoc());
@@ -5564,11 +5571,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
55645571
else
55655572
diag.fixItInsertAfter(argExpr->getEndLoc(),
55665573
getTokenText(tok::r_square));
5567-
diag.flush();
5568-
5569-
if (candidateInfo.size() == 1)
5570-
diagnose(candidateInfo.candidates.front().getDecl(),
5571-
diag::subscript_declared_here);
5574+
showNote();
55725575

55735576
return true;
55745577
}

0 commit comments

Comments
 (0)