Skip to content

[Amendments][#16431] Note emitting amendment & use generic note #16815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ ERROR(could_not_find_subscript_member_did_you_mean,none,
"value of type %0 has no property or method named 'subscript'; "
"did you mean to use the subscript operator?",
(Type))
NOTE(subscript_declared_here,none,
"declared here", ())

ERROR(could_not_find_enum_case,none,
"enum type %0 has no case %1; did you mean %2", (Type, DeclName, DeclName))
Expand Down
17 changes: 10 additions & 7 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5546,9 +5546,16 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
baseType);
diag.highlight(memberRange).highlight(nameLoc.getSourceRange());

if (candidateInfo.closeness != CC_ExactMatch)
auto showNote = [&]() {
diag.flush();
if (candidateInfo.size() == 1)
diagnose(candidateInfo.candidates.front().getDecl(),
diag::kind_declared_here, DescriptiveDeclKind::Subscript);
};
if (candidateInfo.closeness != CC_ExactMatch) {
showNote();
return true;

}
auto toCharSourceRange = Lexer::getCharSourceRangeFromSourceRange;
auto lastArgSymbol = toCharSourceRange(CS.TC.Context.SourceMgr,
argExpr->getEndLoc());
Expand All @@ -5564,11 +5571,7 @@ bool FailureDiagnosis::diagnoseSubscriptMisuse(ApplyExpr *callExpr) {
else
diag.fixItInsertAfter(argExpr->getEndLoc(),
getTokenText(tok::r_square));
diag.flush();

if (candidateInfo.size() == 1)
diagnose(candidateInfo.candidates.front().getDecl(),
diag::subscript_declared_here);
showNote();

return true;
}
Expand Down