Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force Unwrapping false positive #977

Closed
ghost opened this issue Dec 13, 2016 · 6 comments
Closed

Force Unwrapping false positive #977

ghost opened this issue Dec 13, 2016 · 6 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@ghost
Copy link

ghost commented Dec 13, 2016

Declaring a local variable inside a function
var a: [Int]!
is considered force_unwrapping violation. But we are just defining an implicitly unwrapped optional and not force unwrapping it. Seems it is a false positive. It only occurs for Array type and not plain types. e.g. var a: Int! is not considered rule violation.

@marcelofabri marcelofabri added the bug Unexpected and reproducible misbehavior. label Dec 13, 2016
@JamieEdge
Copy link
Contributor

Which version are you using?

I cannot reproduce this with the following example:

Example

@ghost
Copy link
Author

ghost commented Dec 23, 2016

I'm currently using version 0.13.2

Please make sure to define the variable inside a function or method. For example:

func foo() { var x: [Int]! }

The force_unwrapping rule is an opt-in rule. So please also make sure it is opted in.

@marcelofabri
Copy link
Collaborator

I was able to reproduce it on master.

@JamieEdge
Copy link
Contributor

Sorry, moved my test files but not the config! Can now reproduce the issue.

@marcelofabri
Copy link
Collaborator

I think this is actually a consequence of #136.

$ sourcekitten structure --text "func foo() { var x: [Int]! }"
{
  "key.substructure" : [
    {
      "key.kind" : "source.lang.swift.decl.function.free",
      "key.offset" : 0,
      "key.nameoffset" : 5,
      "key.namelength" : 5,
      "key.bodyoffset" : 12,
      "key.bodylength" : 15,
      "key.accessibility" : "source.lang.swift.accessibility.internal",
      "key.length" : 28,
      "key.name" : "foo()"
    }
  ],
  "key.offset" : 0,
  "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
  "key.length" : 28
}

otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue May 29, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue Jun 13, 2017
@marcelofabri
Copy link
Collaborator

Fixed in #1620.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

2 participants