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

Index store reference occurrence incorrectly related for lazy variable

    XMLWordPrintable

    Details

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

      Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
      Target: x86_64-apple-darwin19.6.0

      Description

      Given the following code:

      class MyClass {
          private var someVar = "test"
      
          lazy var someLazyVar: String = {
              return someVar
          }()
      }
      

      The index store incorrectly relates the `someVar` reference within the lazy var body with `MyClass` as opposed to `someLazyVar`.

      The dependency graph is as follows:

      Declaration(class, 'MyClass', explicit, internal, [], 's:17RetentionFixtures7MyClassC', testDoesNotRetainLazyProperty.swift:3:7)
      ··Reference(var.instance, 'someVar', 's:17RetentionFixtures7MyClassC7someVar33_229AED938E4072B048955CC3F10581F2LLSSvp', nil, testDoesNotRetainLazyProperty.swift:7:16)
      ····Reference(function.accessor.getter, nil, 's:17RetentionFixtures7MyClassC7someVar33_229AED938E4072B048955CC3F10581F2LLSSvg', 's:17RetentionFixtures7MyClassC', testDoesNotRetainLazyProperty.swift:7:16)
      ··Reference(struct, 'String', 's:SS', nil, testDoesNotRetainLazyProperty.swift:6:27)
      ··Declaration(var.instance, 'someLazyVar', explicit, internal, [lazy], 's:17RetentionFixtures7MyClassC11someLazyVarSSvp', testDoesNotRetainLazyProperty.swift:6:14)
      ····Declaration(function.accessor.getter, nil, implicit, internal, [lazy], 's:17RetentionFixtures7MyClassC11someLazyVarSSvg', testDoesNotRetainLazyProperty.swift:6:14)
      ····Declaration(function.accessor.setter, nil, implicit, internal, [lazy], 's:17RetentionFixtures7MyClassC11someLazyVarSSvs', testDoesNotRetainLazyProperty.swift:6:14)
      ··Declaration(var.instance, 'someVar', explicit, private, [private], 's:17RetentionFixtures7MyClassC7someVar33_229AED938E4072B048955CC3F10581F2LLSSvp', testDoesNotRetainLazyProperty.swift:4:17)
      ····Declaration(function.accessor.getter, nil, implicit, internal, [private], 's:17RetentionFixtures7MyClassC7someVar33_229AED938E4072B048955CC3F10581F2LLSSvg', testDoesNotRetainLazyProperty.swift:4:17)
      ····Declaration(function.accessor.setter, nil, implicit, internal, [private], 's:17RetentionFixtures7MyClassC7someVar33_229AED938E4072B048955CC3F10581F2LLSSvs', testDoesNotRetainLazyProperty.swift:4:17)
      ··Declaration(function.constructor, nil, implicit, internal, [], 's:17RetentionFixtures7MyClassCACycfc', testDoesNotRetainLazyProperty.swift:3:7)
      

      Note the `someVar` reference is a direct child of `MyClass` rather than `someLazyVar`.

      This issue appears to be specific to lazy variables, when `someLazyVar` is changed to be non-lazy, the `someVar` reference is correctly related.

        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: