Skip to content

[SR-2849] Add a warning for unused parameters #45443

Open
@swift-ci

Description

@swift-ci
Previous ID SR-2849
Radar rdar://problem/31844597
Original Reporter Alex (JIRA User)
Type New Feature
Status In Progress
Resolution
Additional Detail from JIRA
Votes 8
Component/s Compiler
Labels New Feature
Assignee @theblixguy
Priority Medium

md5: a0372c6b5db167e925ad73f87d7f903e

is duplicated by:

Issue Description:

When _ GCC_WARN_UNUSED_PARAMETER_ is enabled unused parameters does not produce warning.

How to reproduce:

  1. Set Yes to Build Settings/Apple LLVM 8.0 Warnings - All languages/Unused Parameters
  2. Add methods or blocks with unused parameters e.g.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // There is usually no need to use `tableView` or `section` parameters for simple tables
    return dataSource.count 
}

or

NotificationCenter.default.addObserver(forName: .UIApplicationWillTerminate, object: nil, queue: nil) { notification in
    // Prepare for app termination
}

Result:
No warnings.

Expected Result:
Xcode should warn about unused parameters: tableView, section and notification.
Also Xcode should suggest to replace these parameters with _ which is already possible to do:

func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
    return dataSource.count 
}

NotificationCenter.default.addObserver(forName: .UIApplicationWillTerminate, object: nil, queue: nil) { _ in
    // Prepare for app termination
}

This setting works as expected in Objective-C (requires __unused attribute to suppress the warning).

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationfeatureA feature request or implementationfunction parametersFeature → declarations: function parameters

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions