Skip to content

[SR-13119] Confusing diagnostic when checking conformance for IUO of generic parameter #55565

@typesanitizer

Description

@typesanitizer
Previous ID SR-13119
Radar rdar://problem/64953106
Original Reporter @typesanitizer
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee srinikhil07 (JIRA)
Priority Medium

md5: cdcccb4342b92c089c6823747fe74efe

Issue 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions