Skip to content

[SR-8616] SourceKit fails to index is pattern object when matched with optionals #51131

@swift-ci

Description

@swift-ci
Previous ID SR-8616
Radar None
Original Reporter rockbruno (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

SourceKit from Xcode 9.4.1 and Xcode 10 beta 6

Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels Bug
Assignee rockbruno (JIRA)
Priority Medium

md5: 22d8979ad62c340d645d65da483e3c6f

is duplicated by:

Issue Description:

struct Bar {}

func match() {
    let foo: Int = 1
    if foo is Bar {
        print("matched")
    }
}

When using the is pattern with non-optionals, SourceKit will correctly index the matched type Bar:

key.kind: source.lang.swift.decl.function.method.instance,
key.name: "match()",
key.usr: "s:4test32qUnffbxEdwYPExPcFQoiHlTghlbgoVIyC5matchyyF",
key.line: 15,
key.column: 10,
key.is_dynamic: 1,
key.entities: [
 {
  key.kind: source.lang.swift.ref.struct,
  key.name: "Int",
  key.usr: "s:Si",
  key.line: 16,
  key.column: 18
 },
 {
  key.kind: source.lang.swift.ref.struct,
  key.name: "Bar",
  key.usr: "s:4test32qUnffbxEdwYPExPcFQoiHlTghlbgoVIyC3BarV",
  key.line: 17,
  key.column: 19
 },
 {
  key.kind: source.lang.swift.ref.function.free,
  key.name: "print(_:separator:terminator:)",
  key.usr: "s:s5printyypd_SS9separatorSS10terminatortF",
  key.line: 18,
  key.column: 13
 }
]

If foo is an optional however, Bar will not index:

struct Bar {} 

func match() { 
    let foo: Int? = 1 
    if foo is Bar { 
        print("matched") 
    } 
}
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "match()",
key.usr: "s:4test32qUnffbxEdwYPExPcFQoiHlTghlbgoVIyC5matchyyF",
key.line: 15,
key.column: 10,
key.is_dynamic: 1,
key.entities: [
 {
  key.kind: source.lang.swift.ref.struct,
  key.name: "Int",
  key.usr: "s:Si",
  key.line: 16,
  key.column: 18
 },
 {
  key.kind: source.lang.swift.ref.function.free,
  key.name: "print(_:separator:terminator:)",
  key.usr: "s:s5printyypd_SS9separatorSS10terminatortF",
  key.line: 18,
  key.column: 13
 }
]

You can see that Xcode will stop highlighting it.
I can gladly take a look at this if someone points me to the right direction!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)expressionsFeature: expressionsindexingArea → source tooling: AST indexingsource toolingArea: IDE support, SourceKit, and other source toolingswift 5.1typesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions