mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This commit adds a fix-it to remove @discardableResult on functions that return Void or Never. The fix-it is at the warning level. A test was added to verify that the fix-it removes the @discardableResult. This issue was reported in SR-3359: https://bugs.swift.org/browse/SR-3359 Changes: TypeCheckAttr.cpp: implemented AttributeChecker::visitDiscardableResultAttr to add a fix-it to remove @discardableResult on functions returning Void or Never. DiagnosticsSema.def: Added a warning with a diagnostic message. LoggingWrappers.swift.gyb, HashedCollections.swift.gyb: Removed @discardableResult on functions returning Void. fixits-apply-all.swift, fixits-apply-all.swift.result: Added tests to verify that @discardableResult is removed from functions returning Void or Never.
27 lines
663 B
Swift
27 lines
663 B
Swift
// This tests whether we accept fixits from warnings without filtering.
|
|
// The particular diagnostics used are not important.
|
|
|
|
// RUN: %swift -typecheck -target %target-triple %s -fixit-all -emit-fixits-path %t.remap
|
|
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
|
|
|
|
func ftest1() {
|
|
let myvar = 0
|
|
}
|
|
|
|
func foo() -> Int {
|
|
do {
|
|
} catch var err {
|
|
goo(err)
|
|
}
|
|
}
|
|
func goo(_ e: Error) {
|
|
|
|
}
|
|
|
|
@warn_unused_result(message="test message")
|
|
func warn_unused_result_removal() -> Int { return 5 }
|
|
|
|
@discardableResult func discardableResultOnVoidFunc() {}
|
|
|
|
@discardableResult func discardableResultOnNeverFunc() -> Never { fatalError() }
|