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

Private types collide when in extensions of the same base type in the same file

    Details

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

      OS X 10.11
      iOS 10
      Xcode 8.0 (8A218a)

      Description

      With following code, we can get a Segmentation Fault 11 during the compiling.

      Unable to find source-code formatter for language: swift. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      import AppKit
      
      extension NSView {
          @objc
          private static func functionA() {
              let a = PrivateStruct(value: "a")
      		NSLog(a.value)
          }
          
          private struct PrivateStruct {
              fileprivate let value: String
          }
      }
      
      extension NSView {
          @objc
          private static func functionB() {
              let b = PrivateStruct(value: "b")
      		NSLog(b.value)
          }
          
          private struct PrivateStruct {
              fileprivate let value: String
          }
      }
      

      I'm guessing that calling a private type in an `@objc` qualified function makes it access control level changed, and since there two private `PrivateStruct` defined in `NSView` and both called in an `@objc` qualified function, so they are collided with each other by itself's name during the compiling.

      We can change the code to be:

      Unable to find source-code formatter for language: swift. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      import AppKit
      
      extension NSView {
          @objc
          private static func functionA() {
              let a = PrivateStruct(value: "a")
      		NSLog(a.value)
          }
          
          private struct PrivateStruct {
              fileprivate let value: String
          }
      }
      
      extension NSView {
          @objc
          private static func functionB() {
              let b = PrivateStruct2(value: "b")
      		NSLog(b.value)
          }
          
          private struct PrivateStruct2 {
              fileprivate let value: String
          }
      }
      

      And at this time, the Segmentation Fault 11 has gone.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                WeZZard WeZZard
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: