Skip to content
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

[Diagnostics] Display correct debug note for compound references typo suggestions #6715

Closed
wants to merge 5 commits into from

Conversation

OscarSwanros
Copy link
Contributor

This PR tries to address the issue where functions with multiple arguments would just be diagnosed incorrectly ignoring their attributes.

Resolves SR-3254.

@OscarSwanros
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Collaborator

@modocache modocache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me! Just needs a few code style changes. Assuming the tests pass, I think this could be merged -- but I'll leave it to someone more familiar with this part of the codebase to approve the pull request.

@@ -555,13 +555,16 @@ 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick: The style guide for C++ in Swift projects is a 80 character column width. You should format this like so:

diagnoseTypoCorrection(TypeChecker &tc,
                       DeclNameLoc loc,
                       ValueDecl *decl,
                       FunctionRefKind refKind) {

Same goes for the line of code below this one: you'll need to split it across two lines for it to fit within 80 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks! Will update accordingly.

@modocache
Copy link
Collaborator

@swift-ci please smoke test

@OscarSwanros
Copy link
Contributor Author

@modocache updated with code-style comments. Thanks for the eyes on this!

ValueDecl *decl,
FunctionRefKind refKind) {

auto name = refKind == FunctionRefKind::Compound ? decl->getFullName() :
Copy link
Member

@CodaFi CodaFi Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM style moves the colon to a new line in-line with the else condition and aligns it with the question mark.

auto name = refKind == FunctionRefKind::Compound ? decl->getFullName()
                                                 : decl->getName();

// 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'}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file and add these tests to Sema/typo_correction.swift (sans * on the expected-note).

@@ -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,
Copy link
Member

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-format with the default LLVM style to have it wrap these for you.

@OscarSwanros
Copy link
Contributor Author

@CodaFi Fixed your comments. Thanks!

FunctionRefKind refKind) {

auto name = refKind == FunctionRefKind::Compound ? decl->getFullName()
: decl->getName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you must add the quotes back or it'll fall any existing typo correction tests that rely on it.

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other type that would work in this case?

@CodaFi
Copy link
Member

CodaFi commented Jun 1, 2017

@OscarSwanros What's the status of this pull request? If you're still interested in this bug fix, could you rebase this pull request and give me a ping?

@CodaFi
Copy link
Member

CodaFi commented Jul 12, 2017

This patch has fallen behind after a month. @OscarSwanros feel free to reopen this when you find the time.

@CodaFi CodaFi closed this Jul 12, 2017
@OscarSwanros
Copy link
Contributor Author

Oh, sorry @CodaFi — have been swamped and missed your notification. Will try to find the time soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants