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

[SR-6443] SourceKit returns wrong case statement key length when string interpolation is used #48993

Open
swift-ci opened this issue Nov 20, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6443
Radar None
Original Reporter ilyapuchka (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 4
Component/s Source Tooling
Labels Bug
Assignee None
Priority Medium

md5: bbe4643af19284a5306a637123bde4ce

Issue Description:

The length of `source.lang.swift.stmt.case` returned wrong when it has string interpolation.

Here is example with using true/false as interpolated value, but results will be wrong for any other value.

$ sourcekitten structure --text 'switch { default: return "\(true)" }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 27,  // should be 25
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9

spaces after interpolation are not counted:

$ sourcekitten structure --text 'switch { default: return "\(true) " }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 25,  // should be 26
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9

any other character after interpolation are counted, but results are still wrong

$ sourcekitten structure --text 'switch { default: return "\(true)1" }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 25,  // should be 26
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9
$ sourcekitten structure --text 'switch { default: return "\(true)12" }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 26,  // should be 27
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9

string interpolation followed by unicode:

$ sourcekitten structure --text 'switch { default: return "\(true) π" }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 26, // should be 28
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9

unicode before string interpolation:

$ sourcekitten structure --text 'switch { default: return "π \(true)" }'"key.kind" : "source.lang.swift.stmt.case",
          "key.length" : 30, // should be 28
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 9

Reference: jpsim/SourceKitten#444 (comment)

@belkadan
Copy link
Contributor

cc @nkcsgexi

@marcelofabri
Copy link
Contributor

I just verified that this still happens on master. Any directions on where to look to try to fix this?

@belkadan
Copy link
Contributor

…cc @rintaro?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants