swiftlang/swift

[SR-7933] SourceKit double-counts escaping and autoclosure attributes

Open

#50,468 opened on Jun 8, 2018

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Swift (10,719 forks)batch import
good first issueimprovement

Repository metrics

Stars
 (69,989 stars)
PR merge metrics
 (Avg merge 8d 17h) (510 merged PRs in 30d)

Description

Previous ID SR-7933
Radar None
Original Reporter @natecook1000
Type Improvement
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.

Contributor guide