Skip to content

[SR-7307] Warn when a block contains nothing but a defer statement #49855

@jckarter

Description

@jckarter
Previous ID SR-7307
Radar None
Original Reporter @jckarter
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee @vguerra
Priority Medium

md5: 9b4fc281235964efdf067b80f3a93de4

Issue Description:

A user used to Go's defer, or expecting Go-like behavior from first principles, may write something like this:

if x {
  defer { thing_i_only_want_to_happen_when_x() }
}

which is going to run thing_i_only_want_to_happen_when_x at the exit of the if scope rather than at the end of the function. If a block contains nothing but a `defer`, the defer is useless, and we should probably warn to that effect.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics qualityBug: The quality of compiler diagnosticsgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions