Uploaded image for project: 'Swift'
  1. Swift
  2. SR-14181

Index store does not relate constructor referenced via Self

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Source Tooling
    • Labels:
      None
    • Environment:

      Swift 5.3 & 5.4 beta

      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
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            Leitch Ian Leitch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: