swiftlang/swift

[SR-14181] Index store does not relate constructor referenced via Self

swift-ci opened this issue · 3 comments

Previous ID SR-14181
Radar rdar://problem/74189756
Original Reporter Leitch (JIRA User)
Type Bug
Environment

Swift 5.3 & 5.4 beta

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

md5: 14bd45e97ccd316281a8cb702253758c

Issue Description:

Given the following code:

struct MyStruct {
    static let instance = Self(someVar: 123)
    let someVar: Int

    init(someVar: Int) {
        self.someVar = someVar
    }
}

The index store does not relate the constructor at all. For the purposes of identifying unused code, it's not possible to determine that the constructor is in use. It's debatable which definition should hold the constructor relation. Either the struct or the property would suffice, though the implicit property setter would be my preference.

1:8 | struct/Swift | MyStruct | s:14swift_ide_test8MyStructV | Def | rel: 0
2:16 | static-property/Swift | instance | s:14swift_ide_test8MyStructV8instanceACvpZ | Def,RelChild | rel: 1
  RelChild | struct/Swift | MyStruct | s:14swift_ide_test8MyStructV
2:16 | static-method/acc-get/Swift | getter:instance | s:14swift_ide_test8MyStructV8instanceACvgZ | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | static-property/Swift | instance | s:14swift_ide_test8MyStructV8instanceACvpZ
2:16 | static-method/acc-set/Swift | setter:instance | s:14swift_ide_test8MyStructV8instanceACvsZ | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | static-property/Swift | instance | s:14swift_ide_test8MyStructV8instanceACvpZ
3:9 | instance-property/Swift | someVar | s:14swift_ide_test8MyStructV7someVarSivp | Def,RelChild | rel: 1
  RelChild | struct/Swift | MyStruct | s:14swift_ide_test8MyStructV
3:9 | instance-method/acc-get/Swift | getter:someVar | s:14swift_ide_test8MyStructV7someVarSivg | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | instance-property/Swift | someVar | s:14swift_ide_test8MyStructV7someVarSivp
3:9 | instance-method/acc-set/Swift | setter:someVar | s:14swift_ide_test8MyStructV7someVarSivs | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | instance-property/Swift | someVar | s:14swift_ide_test8MyStructV7someVarSivp
3:18 | struct/Swift | Int | s:Si | Ref | rel: 0
5:5 | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc | Def,RelChild | rel: 1
  RelChild | struct/Swift | MyStruct | s:14swift_ide_test8MyStructV
5:10 | param/Swift | someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivp | Def,RelChild | rel: 1
  RelChild | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc
5:10 | function/acc-get/Swift | getter:someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivg | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | param/Swift | someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivp
5:10 | function/acc-set/Swift | setter:someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivs | Def,Impl,RelChild,RelAcc | rel: 1
  RelChild,RelAcc | param/Swift | someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivp
5:19 | struct/Swift | Int | s:Si | Ref,RelCont | rel: 1
  RelCont | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc
6:14 | instance-property/Swift | someVar | s:14swift_ide_test8MyStructV7someVarSivp | Ref,Writ,RelCont | rel: 1
  RelCont | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc
6:14 | instance-method/acc-set/Swift | setter:someVar | s:14swift_ide_test8MyStructV7someVarSivs | Ref,Call,Impl,RelRec,RelCall,RelCont | rel: 2
  RelCall,RelCont | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc
  RelRec | struct/Swift | MyStruct | s:14swift_ide_test8MyStructV
6:24 | param/Swift | someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivp | Ref,Read,RelCont | rel: 1
  RelCont | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc
6:24 | function/acc-get/Swift | getter:someVar | s:14swift_ide_test8MyStructV7someVarACSi_tcfcADL_Sivg | Ref,Call,Impl,RelCall,RelCont | rel: 1
  RelCall,RelCont | constructor/Swift | init(someVar:) | s:14swift_ide_test8MyStructV7someVarACSi_tcfc

Comment by Ian Leitch (JIRA)

/cc @benlangmuir

keith commented

dup of #64686 which is fixed on main and submitted to 5.9 for a cherry pick