Skip to content

[SR-2661] Usability regression re: fatalError() within function literals #45266

@swift-ci

Description

@swift-ci
Previous ID SR-2661
Radar None
Original Reporter Darkmoon_UK (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 3.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression, TypeChecker
Assignee @slavapestov
Priority Medium

md5: d96afbd5d3223a6d24b62985a71c1cb6

Issue Description:

The transition to using the 'Never' type as the underlying mechanism for no-return functions such as fatalError() has caused a serious usability regression preventing their use within function literals, where it was possible before.

Consider the following cases:

// This compiles in both Swift 2 and 3
func test1() -> Int {
    fatalError()
}

// This compiled in Swift2 but no longer does in Swift 3
let test2 : () -> Int = {
    fatalError()
}

// Compiles in Swift 3
let test2 : () -> Int = {
    if false { return 0 }
    fatalError()
}

I filed a bug report with Apple which was closed as 'intended behaviour' but I am unsatisfied by this answer. The third case in particular highlights this as a complex inconsistency that should be considered for a potential fix, or at least deserves a detailed explanation.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfregressionswift 3.0type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions