You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-778 Forgetting the in keyword can sometimes lead to compiling code
Issue Description:
The Standard Library currently has almost 400 @warn_unused_result attributes and, as demonstrated here, that is not enough.
(I am a fan of the proposal to make this warning default for all non-Void returning funcs.)
I generated a list of potential missing @warn_unused result attributes by searching the Standard Library's generated interface for non void public funcs without the attribute, using something like: t\npublic func [^\n][-][>][^\n]
From that list I wrote these two functions to show my findings / some low hanging fruit for contributors:
func asExpectedThisFuncHasWarningsOnEveryLine() {
1.0 + 2.0
1.0 - 2.0
1.0 * 2.0
1.0 / 2.0
1.0 % 2.0
1.0 == 2.0
1.0 != 2.0
1.0 < 2.0
1.0 > 2.0
1.0 <= 2.0
1.0 >= 2.0
}
func butSurprisinglyThisFuncHasNoWarningsAtAll() {
// Missing @warn_unused_result for these Int operators:
1 + 2
1 - 2
1 * 2
1 / 2
1 % 2
1 == 2
1 != 2
1 < 2
1 > 2
1 <= 2
1 >= 2
1 << 2
1 >> 2
1 & 2
1 | 2
1 ^ 2
// And it's the same for UInt, UInt8-64 and Int8-64.
// And also for these:
class C : NonObjectiveCBase {}; var c = C(); var oc: C? = C()
typealias MBP = ManagedBufferPointer<Void, Void>
isUniquelyReferenced(&c)
isUniquelyReferencedNonObjC(&c)
isUniquelyReferencedNonObjC(&oc)
MBP(unsafeBufferObject: c) == MBP(unsafeBufferObject: c)
zip([1, 2, 3], ["one", "two", "three"])
}
EDIT:
Also, as suggested by @belkadan in the swift evolution mailing list, I'm adding the related issue of missing warning(s) for unused literals, like eg:
func perhapsConfusing() {
let s =
"Since this function compiles fine. One might "
"think that string literals in Swift can be "
"written like this. But that is not the case. "
"Only the first string literal will be printed."
"The rest (including eg this) will be silently "
"ignored."
12.34 // As will this.
print(s) // Will print: "Since this function compiles fine. One might "
}
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 8a2d58a566fb9e188b29e87376a9f71e
relates to:
Issue Description:
The Standard Library currently has almost 400 @warn_unused_result attributes and, as demonstrated here, that is not enough.
(I am a fan of the proposal to make this warning default for all non-Void returning funcs.)
I generated a list of potential missing @warn_unused result attributes by searching the Standard Library's generated interface for non void public funcs without the attribute, using something like:
t\npublic func [^\n][-][>][^\n]
From that list I wrote these two functions to show my findings / some low hanging fruit for contributors:
EDIT:
Also, as suggested by @belkadan in the swift evolution mailing list, I'm adding the related issue of missing warning(s) for unused literals, like eg:
The text was updated successfully, but these errors were encountered: