Skip to content

[4.1][CursorInfo] Fix crash on instance variables used directly in if or for when declared in a generic context #14190

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

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Jan 26, 2018

CCC Info

  • Radar: rdar://problem/36871908
  • Explanation:
    Invoking the cursor info request on a instance variable used directly in an if condition or for in clause would crash SourceKit if the instance variable was in a generic context. E.g:
class SomeType<T> {
  let test: Bool = false
  let items: [Int] = []
  func foo() {
    if test {} // crashes on test
    for in items {} // crashes on items
  }
}

We were getting an incorrect containing type for the instance variable (Bool rather than SomeType<T>) as our logic for matching cursor locations in MemberRefExprs was based on the source location of the . which isn't present in this case.

  • Risk: Low. The change affects sourcekitd cursor info request when invoked on MemberRefExprs.
  • Scope of issue: Jump-to-definition, quick help and refactoring were crashing sourcekit on these references
  • Origination: Crash reports
  • Reviewed by: Xi Ge
  • Testing: Added regression test

PR for master: #14171
PR for swift-5.0-branch: #14189

…or when declared in a generic context

For example:
class Foo<T> {
  let test: Bool = false
  let items: [Int] = []
  func foo() {
    if test {} // crashes on test
    for i in items {} // crashes on items
  }
}

We were picking up the incorrect containing type (Bool rather than Foo<T>).
Resolves rdar://problem/36871908.
@nathawes nathawes requested a review from nkcsgexi January 26, 2018 18:44
Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

LGTM!

@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes changed the title [CursorInfo] Fix crash on instance variables used directly in if or for when declared in a generic context [4.1][CursorInfo] Fix crash on instance variables used directly in if or for when declared in a generic context Jan 26, 2018
@nathawes nathawes merged commit ca1cb64 into swiftlang:swift-4.1-branch Jan 26, 2018
@nathawes nathawes deleted the rdar36871908-cursor-info-crash-on-ivar-of-generic-context-used-in-if-or-for-4.1 branch January 26, 2018 22:00
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.

2 participants