Skip to content

[SR-10569] Compiler is confused when both dot syntax and forced unwrapping are used. #52969

@YOCKOW

Description

@YOCKOW
Previous ID SR-10569
Radar None
Original Reporter @YOCKOW
Type Bug
Environment

Swift: swift-DEVELOPMENT-SNAPSHOT-2019-04-16-a
OS: macOS mojave 10.14.4

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee None
Priority Medium

md5: dab68829c010ec40062a551a4d76d0c6

relates to:

Issue Description:

Code:

struct  S {
  init?(_ string: String) {}
}
let s: S = .init("Failable")!

Result:

dot+forceunwrap.swift:4:13: error: value of optional type 'S?' must be unwrapped to a value of type 'S'
let s: S = .init("Failable")!
            ^
dot+forceunwrap.swift:4:13: note: coalesce using '??' to provide a default when the optional value contains 'nil'
let s: S = .init("Failable")!
            ^
           (                 ?? <#default value#>)
dot+forceunwrap.swift:4:13: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
let s: S = .init("Failable")!
            ^
                            !
dot+forceunwrap.swift:4:29: error: cannot force unwrap value of non-optional type 'S'
let s: S = .init("Failable")!
           ~~~~~~~~~~~~~~~~~^

Expected Behavior:

Meaningful fixit is viewed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsforce-valueFeature → expressions: Force-value aka force-unwrap expressionimplicit member expressionsFeature → expressions: Implicit member expressionsswift 5.0type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions