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-7933] SourceKit double-counts escaping and autoclosure attributes #50468

Open
natecook1000 opened this issue Jun 8, 2018 · 2 comments
Open
Labels

Comments

@natecook1000
Copy link
Member

Previous ID SR-7933
Radar None
Original Reporter @natecook1000
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels Improvement, StarterBug
Assignee None
Priority Medium

md5: 065c0c3c9adc792d7d7203c32bd04ee2

Issue Description:

The @escaping and @autoclosure attributes are mapped differently from other attributes. For example, given this source code:

func a(_ b: @escaping () -> Bool) {}
@discardableResult func b() -> Int { return 0 }
func c(_ b: @autoclosure () -> Bool) {}

SourceKit yields this syntax map (unrelated pieces elided):

{
  key.offset: 0,
  key.length: 125,
  key.diagnostic_stage: source.diagnostic.stage.swift.parse,
  key.syntaxmap: [
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.id,
      key.offset: 12,
      key.length: 9
    },
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 13,
      key.length: 8
    },
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 37,
      key.length: 18
    },
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.id,
      key.offset: 97,
      key.length: 12
    },
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 98,
      key.length: 11
    },
    ...
  ]
}

The "source.lang.swift.syntaxtype.attribute.builtin" keys should have the offset and length of the "source.lang.swift.syntaxtype.attribute.id" keys, which in turn shouldn't be emitted.

@swift-ci
Copy link
Collaborator

Comment by Nathan Hitchings (JIRA)

Based on the description, I gather that the syntax map should look like this:

{
  key.offset: 0,
  key.length: 125,
  key.diagnostic_stage: source.diagnostic.stage.swift.parse,
  key.syntaxmap: [
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 12,
      key.length: 9
    },
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 37,
      key.length: 18
    },
    ...,
    {
      key.kind: source.lang.swift.syntaxtype.attribute.builtin,
      key.offset: 97,
      key.length: 12
    },
    ...
  ]
}

Is that correct?

@natecook1000
Copy link
Member Author

That looks correct to me!

@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
Projects
None yet
Development

No branches or pull requests

2 participants