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

Cannot use `super` in lazy property: 'super' cannot be used outside of class members

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Tested with Swift 4.2.1 (Xcode 10.1) and Swift 5 from Xcode 10.2 beta (swiftlang-1001.0.45.7 clang-1001.0.37.7).

      Description

      I’m not sure this is a bug or if this works as expected:

      class Foo {
          var name = "Default Name"
      }
      
      class Bar: Foo {
          lazy var fullName: String = {
              return super.name // error: 'super' cannot be used outside of class members
          }()
      }
      

      Is there a good reason why super isn’t permitted here? Replacing super with self works fine, as I’d expect because the instance must be fully initialized when lazy properties are accessed.

        Attachments

          Activity

            People

            • Assignee:
              suyashsrijan Suyash Srijan
              Reporter:
              marco.masser Marco Masser
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: