Skip to content

[SR-13815] Confusing unwrapping diagnostic when using implicit member access on Optionals. #56212

@swift-ci

Description

@swift-ci
Previous ID SR-13815
Radar rdar://problem/71082108
Original Reporter iDevid (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee iDevid (JIRA)
Priority Medium

md5: 790bfd0e832f8f87224b0af0f4e3cd77

is duplicated by:

  • SR-13842 Compiler fails to type check optional UIImage when SwiftUI is imported

Issue Description:

struct Object {
    init?() {
        return nil
    }
}

struct Test {
    let id: Int
    let object: Object?
}

Test(id: 1, object: nil)
Test(id: 1, object: Object())
Test(id: 1, object: .init()) // this will fail

As you can see, the Test Struct contains an id along with an optional Object property.

Passing the Object's .init() in the Test initializer will lead to the error:

Value of optional type 'Object?' must be unwrapped to a value of type 'Object'

This diagnostic doesn't make it clear what the issue is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationtype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions