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

Confusing diagnostic when checking conformance for IUO of generic parameter

    XMLWordPrintable

    Details

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

      Description

      Consider the following code:

      struct S<T>: Codable {
        var s: T!
      } 

      With Xcode 12 beta 1, this generates the following diagnostic:

      tmp.swift:1:8: error: type 'S' does not conform to protocol 'Decodable'
      struct S<T>: Codable {
             ^
      Swift.Decodable:2:5: note: protocol requires initializer 'init(from:)' with type 'Decodable'
          init(from decoder: Decoder) throws
          ^
      tmp.swift:2:9: note: cannot automatically synthesize 'Decodable' because 'T?' does not conform to 'Decodable'
          var x: T!
              ^
      tmp.swift:1:8: error: type 'S' does not conform to protocol 'Encodable'
      struct S<T>: Codable {
             ^
      Swift.Encodable:2:10: note: protocol requires function 'encode(to:)' with type 'Encodable'
          func encode(to encoder: Encoder) throws
               ^
      tmp.swift:2:9: note: cannot automatically synthesize 'Encodable' because 'T?' does not conform to 'Encodable'
          var x: T!
              ^ 

      The diagnostic says T? does not conform to Encodable but it should be saying T! instead, because the user wrote T!.

      At the moment, the code example crashes with master, which is tracked in SR-13117.

        Attachments

          Activity

            People

            Assignee:
            srinikhil07 Nikhil
            Reporter:
            theindigamer Varun Gandhi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: