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

A runtime crash

    XMLWordPrintable

    Details

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

      Swift Development Snapshot 2018-10-24(a)

      Description

      protocol _Decodable: Decodable {}
      
      extension _Decodable {
          static func decode(from data: Data) throws -> Self {
              let decoder = JSONDecoder()
              return try decoder.decode(self, from: data)
          }
      }
      
      private class _JSONDecoder1: _JSONDecoder {
      }
      
      
      extension JSONDecoder {
          func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: _Decodable {
              let topLevel = try JSONSerialization.jsonObject(with: data, options: [JSONSerialization.ReadingOptions(rawValue: 1 << 15)])
              let decoder = _JSONDecoder1( // _JSONDecoder dose not crash
                  referencing: topLevel,
                  options: JSONDecodingOptions(
                      dateDecodingStrategy: dateDecodingStrategy,
                      dataDecodingStrategy: dataDecodingStrategy,
                      nonConformingFloatDecodingStrategy: nonConformingFloatDecodingStrategy,
                      keyDecodingStrategy: keyDecodingStrategy,
                      userInfo: userInfo
                  )
              )
              return try T(from: decoder)
          }
      }
      

      This code will cause a runtime crash, and the error message is useless.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              linqingmo LinQingmo
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: