Skip to content

Fix Issue #63993 by improving out-of-place binding diagnostic and reflecting 'var' or 'let' binding pattern #64422

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
Mar 19, 2023

Conversation

Rajveer100
Copy link
Contributor

Fixes Issue #63993

Added a new 'DescriptivePatternKind' declaration with its methods and functionality similar to 'DescriptiveDeclKind', thereby allowing binding pattern check in the appropriate places for 'var' or 'let' and improving the overall diagnostics.

@Rajveer100
Copy link
Contributor Author

@hamishknight
In my understanding, these are the following additions that remain:

  • StringRef Pattern::getDescriptivePatternKindName(DescriptivePatternKind K)
  • DescriptivePatternKind Pattern::getDescriptiveKind() const
  • +Misc.

@hamishknight hamishknight self-requested a review March 16, 2023 11:33
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Definitely on the right track! The remaining items on your list sound good to me

@Rajveer100
Copy link
Contributor Author

Done!

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Looks great! I have a few more comments, but otherwise this looks good to me. A couple more things that also need doing before we can land this:

  1. Can you run git clang-format over this change? If not already installed, you should be able to install clang-format with homebrew.
  2. You'll need to update any tests that have had their diagnostics changed. Off the top of my head, I know there are a couple of cases in test/Sema/redeclaration-checking.swift that will need changing to expect 'let' binding pattern instead of 'var' binding pattern (and there's a FIXME comment you can now remove).

@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Mar 18, 2023

Looks great! I have a few more comments, but otherwise this looks good to me. A couple more things that also need doing before we can land this:

  1. Can you run git clang-format over this change? If not already installed, you should be able to install clang-format with homebrew.
  2. You'll need to update any tests that have had their diagnostics changed. Off the top of my head, I know there are a couple of cases in test/Sema/redeclaration-checking.swift that will need changing to expect 'let' binding pattern instead of 'var' binding pattern (and there's a FIXME comment you can now remove).

Hey there, I will make the changes, thanks for the review!

@Rajveer100
Copy link
Contributor Author

  1. You'll need to update any tests that have had their diagnostics changed. Off the top of my head, I know there are a couple of cases in test/Sema/redeclaration-checking.swift that will need changing to expect 'let' binding pattern instead of 'var' binding pattern (and there's a FIXME comment you can now remove).

I don't find any such case in the mentioned file, no 'FIXME' comment as well. The only similar cases I observed were the ones with the 'redeclaration' issue or similar.

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-63993 branch 2 times, most recently from 3318d8c to a76965c Compare March 19, 2023 11:39
@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Mar 19, 2023

Apart from that, I have done the changes!

@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Mar 19, 2023

Hey! Looks like my codebase isn't updated since a while, cause the number of LOC in the file referenced is barely around ~120.

Probably I should git pull.

@hamishknight
Copy link
Contributor

Ah that makes sense, be sure to git pull --rebase to avoid adding a merge to the branch

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-63993 branch 2 times, most recently from ebe51fb to 99b756f Compare March 19, 2023 13:46
@Rajveer100
Copy link
Contributor Author

Well, that's done, hope there aren't any more test files which need changes!

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-63993 branch from 99b756f to 0475a97 Compare March 19, 2023 13:54
@Rajveer100 Rajveer100 closed this Mar 19, 2023
@Rajveer100 Rajveer100 reopened this Mar 19, 2023
@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Mar 19, 2023

Mistakenly had closed this pull request for a second!
Apologies for that!

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-63993 branch from 0475a97 to c34f099 Compare March 19, 2023 13:57
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Wonderful, thank you!

@hamishknight
Copy link
Contributor

Well, that's done, hope there aren't any more test files which need changes!

Let's find out :)

@swift-ci please test

@Rajveer100
Copy link
Contributor Author

Observed an issue!

I ran the tests specifically for the test file in context:

/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:113:6: error: expected error not produced
  // expected-error@-1 {{invalid redeclaration of 'x'}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:114:6: error: expected note not produced
  // expected-note@-2 {{'x' previously declared here}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:117:6: error: expected error not produced
  // expected-error@-1 {{invalid redeclaration of 'x'}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:118:6: error: expected note not produced
  // expected-note@-2 {{'x' previously declared here}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:122:8: error: expected error not produced
    // expected-error@-1 {{invalid redeclaration of 'x'}}
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:123:8: error: expected note not produced
    // expected-note@-2 {{'x' previously declared here}}
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:130:6: error: expected error not produced
  // expected-error@-2 {{invalid redeclaration of 'x'}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/rajveersingh/Desktop/swift-project/swift/test/Sema/redeclaration-checking.swift:131:6: error: expected note not produced
  // expected-note@-3 {{'x' previously declared here}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Rajveer100
Copy link
Contributor Author

Failed Tests (1):
  Swift(macosx-arm64) :: Sema/redeclaration-checking.swift


Testing Time: 0.41s
  Excluded: 8811
  Failed  :    1

4 warning(s) in tests

@hamishknight
Copy link
Contributor

@Rajveer100 Did you rebuild after rebasing your branch? Those test failures sound like you have a build that was done before #63994

@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Mar 19, 2023

Ah yes, forgot about that!
Let me do that! :)

@Rajveer100
Copy link
Contributor Author

A question!
Could you briefly differentiate between normal tests and smoke tests, also when they are used and when not.

@hamishknight
Copy link
Contributor

hamishknight commented Mar 19, 2023

Sure, the details are documented in https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#pull-request-testing. In short, a full test runs more configurations (e.g different targets, different optimization levels) than a smoke test. Personally I tend on the side of doing a full test unless the change is fairly trivial (e.g something like a light refactoring), though honestly it's probably overkill for a change like this.

@Rajveer100
Copy link
Contributor Author

All checks passed!

@hamishknight hamishknight merged commit a563db6 into swiftlang:main Mar 19, 2023
@Rajveer100 Rajveer100 deleted the branch-for-issue-63993 branch March 20, 2023 09:01
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.

Improve out-of-place binding diagnostic to reflect whether the binding was written as 'var' or 'let'
2 participants