-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
@discardableResultFeature → attributes: The @discardableResult attributeFeature → attributes: The @discardableResult attributeattributesFeature: Declaration and type attributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationfix-itsFeature: diagnostic fix-itsFeature: diagnostic fix-itsparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserswift 5.9
Description
Description
When placing @discardableResult
on a variable declaration, the suggested fix it results in another fix-it, because @discardableResult
doesnt seem to work on property declarations:
struct Foo {
// suggested fix-it: Attribute can only be applied to declarations, not types - Replace 'var foo: @discardableResult ' with '@discardableResult var foo: '
var foo: @discardableResult () -> Int
}
Using the fix-it results in the following, which requires another fix-it:
struct Foo {
// suggested fix-it: '@discardableResult' attribute cannot be applied to this declaration - Remove '@discardableResult '
@discardableResult var foo: () -> Int
}
which finally results in code that compiles, albeit without the result that the developer desires:
struct Foo {
var foo: () -> Int
}
Steps to reproduce
Place @discardableResult
on variable declaration's type.
Expected behavior
Fix it to completely remove @discardableResult
, until @discardableResult
is supported on property decls.
Environment
- Swift compiler version info 5.9
- Xcode version info 14.3
- Deployment target: any
Metadata
Metadata
Assignees
Labels
@discardableResultFeature → attributes: The @discardableResult attributeFeature → attributes: The @discardableResult attributeattributesFeature: Declaration and type attributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationfix-itsFeature: diagnostic fix-itsFeature: diagnostic fix-itsparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserswift 5.9