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

Compiler crash when extending type with Codable

    XMLWordPrintable

    Details

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

      swift-4.0-DEVELOPMENT-SNAPSHOT-2017-05-15-a.xctoolchain

      Description

      Simple program results in a compiler crash:

      import Foundation
      
      public struct SaveOptions  {
          public init(includeText: Bool) {
              self.includeText = includeText
          }
          public var includeText: Bool
      }
      
      extension SaveOptions: Codable {}
      
      let encoder = JSONEncoder()
      let decoder = JSONDecoder()
      let saveOptions = SaveOptions(includeText: true)
      let data = try encoder.encode(saveOptions)
      let json = String(data: data, encoding: .utf8)!
      let type = try decoder.decode(SaveOptions.self, from: data)
      
      print("encoded: \(data)")
      print("json: \(json)")
      print("type: \(type)")
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              huon Huon Wilson
              Reporter:
              owensd David Owens
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: