- Notifications
You must be signed in to change notification settings - Fork 10.6k
[Diagnostics] Display correct debug note for compound references typo suggestions #6715
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
Changes from 4 commits
52847c9 3342575 967381c f7a2578 91bfa0b File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -555,13 +555,21 @@ void TypeChecker::performTypoCorrection(DeclContext *DC, DeclRefKind refKind, | |
| } | ||
| | ||
| static InFlightDiagnostic | ||
| diagnoseTypoCorrection(TypeChecker &tc, DeclNameLoc loc, ValueDecl *decl) { | ||
| diagnoseTypoCorrection(TypeChecker &tc, | ||
| DeclNameLoc loc, | ||
| ValueDecl *decl, | ||
| FunctionRefKind refKind) { | ||
| | ||
| auto name = refKind == FunctionRefKind::Compound ? decl->getFullName() : | ||
| ||
| decl->getName(); | ||
| | ||
| if (auto var = dyn_cast<VarDecl>(decl)) { | ||
| // Suggest 'self' at the use point instead of pointing at the start | ||
| // of the function. | ||
| | ||
| if (var->isSelfParameter()) | ||
| return tc.diagnose(loc.getBaseNameLoc(), diag::note_typo_candidate, | ||
| decl->getName().str()); | ||
| name); | ||
| } | ||
| | ||
| if (!decl->getLoc().isValid() && decl->getDeclContext()->isTypeContext()) { | ||
| | @@ -579,13 +587,15 @@ diagnoseTypoCorrection(TypeChecker &tc, DeclNameLoc loc, ValueDecl *decl) { | |
| } | ||
| } | ||
| | ||
| return tc.diagnose(decl, diag::note_typo_candidate, decl->getName().str()); | ||
| return tc.diagnose(decl, diag::note_typo_candidate, name); | ||
| } | ||
| | ||
| void TypeChecker::noteTypoCorrection(DeclName writtenName, DeclNameLoc loc, | ||
| const LookupResult::Result &suggestion) { | ||
| void TypeChecker::noteTypoCorrection(DeclName writtenName, | ||
| DeclNameLoc loc, | ||
| const LookupResult::Result &suggestion, | ||
| FunctionRefKind refKind) { | ||
| auto decl = suggestion.Decl; | ||
| auto &&diagnostic = diagnoseTypoCorrection(*this, loc, decl); | ||
| auto &&diagnostic = diagnoseTypoCorrection(*this, loc, decl, refKind); | ||
| | ||
| DeclName declName = decl->getFullName(); | ||
| | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2083,7 +2083,8 @@ class TypeChecker final : public LazyResolver { | |
| unsigned maxResults = 4); | ||
| | ||
| void noteTypoCorrection(DeclName name, DeclNameLoc nameLoc, | ||
| const LookupResult::Result &suggestion); | ||
| const LookupResult::Result &suggestion, | ||
| FunctionRefKind refKind = FunctionRefKind::Unapplied); | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not 100% sure this is the right type for this. For names that aren't function references that go through typo correction this is kind of nonsensical. Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any other type that would work in this case? | ||
| | ||
| /// Check if the given decl has a @_semantics attribute that gives it | ||
| /// special case type-checking behavior. | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // RUN: %target-typecheck-verify-swift | ||
| | ||
| func foo(x: Int) {} // expected-note * {{did you mean 'foo(x:)'?}} | ||
| let f = foo(_:) // expected-error {{use of unresolved identifier 'foo'}} | ||
| ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't necessarily have to fold the entire signature over, just those that go over the line-limit. If it makes it easier, you can run
clang-formatwith the default LLVM style to have it wrap these for you.