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

Error when adding static stored properties to Objective-C classes in extensions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      Swift 2.2: 7.3.1 (7D1014)
      Swift 3.0: Xcode 8.0 beta 6 (8S201h), master ae69ffb2

      Description

      When adding a static stored property to an Objective-C classes in an extension, the compiler fails with the error message A declaration cannot be both 'final' and 'dynamic' which is not associated with any source location.

      import Foundation
      
      public class TestClass: NSObject {
      }
      
      extension TestClass {
        class let x = 5
      }
      

      If TestClass does not inherit from NSObject (and is hence not @objc) the code compiles fine.

      If you write class let x = 5 instead of static let x = 5, the compiler fails with the error message Class stored properties not supported in classes; did you mean 'static'? suggesting the static keyword.

      If adding static stored properties to @objc classes is not supported in extensions, we should produce a diagnostic that clearly points out the issue (including a source location).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              ahoppen Alex Hoppen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: