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

Incorrect force_unwrapping violation with array IUO #1710

Closed
ldiqual opened this issue Jul 25, 2017 · 3 comments
Closed

Incorrect force_unwrapping violation with array IUO #1710

ldiqual opened this issue Jul 25, 2017 · 3 comments
Labels
repro-needed Issues that cannot be reproduced or miss proper descriptive examples.

Comments

@ldiqual
Copy link

ldiqual commented Jul 25, 2017

On 0.20.1, the following code triggers a force_unwrapping violation:

var invites: [Invite]!

image

I believe it is due to #1620

@marcelofabri marcelofabri added the repro-needed Issues that cannot be reproduced or miss proper descriptive examples. label Jul 26, 2017
@marcelofabri
Copy link
Collaborator

Are you sure you're using 0.20.1? I couldn't reproduce it.

$ echo "var invites: [Invite]\!" | swiftlint lint --use-stdin --enable-all-rules 
Loading configuration from '.swiftlint.yml'
<nopath>:1:1: warning: Explicit Top Level ACL Violation: Top-level declarations should specify Access Control Level keywords explicitly. (explicit_top_level_acl)
<nopath>:1:1: warning: Implicitly Unwrapped Optional Violation: Implicitly unwrapped optionals should be avoided when possible. (implicitly_unwrapped_optional)
<nopath>:1: warning: File Header Violation: Files should have consistent header comments. (file_header)
Done linting! Found 3 violations, 0 serious in 1 file.

@otaviolima
Copy link
Contributor

otaviolima commented Jul 26, 2017

It is reproducible with 0.20.1.

It is triggered when an implicitly unwrapped array/dictionary variable is declared inside a function, closure, brackets, etc.

For instance:

$ echo "if cond { var invites: [Invite]! }" | swiftlint lint --use-stdin --enable-all-rules
<nopath>:1:32: warning: Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)
Done linting! Found 1 violation, 0 serious in 1 file.

Or:

$ echo "abc { var invites: [Invite]! }" | swiftlint lint --use-stdin --enable-all-rules
<nopath>:1:28: warning: Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)
Done linting! Found 1 violation, 0 serious in 1 file.

#1620 should not have introduced this. But I was not aware of SourceKitten limitation ( #136, jpsim/SourceKitten#151) when reporting local variable declaration at the time I wrote the fix for subscripts.

I've been trying to fix it for a while but no progress so far.

@marcelofabri
Copy link
Collaborator

marcelofabri commented Jul 26, 2017

But then, this is a duplicate of #136. There's not much we can do other than fixing the issue in SourceKit itself (SR-5057).

@marcelofabri marcelofabri marked this as a duplicate of #136 Jul 26, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue Jul 27, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue Jul 27, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue Jul 28, 2017
otaviolima added a commit to otaviolima/SwiftLint that referenced this issue Jul 28, 2017
@jpsim jpsim closed this as completed in fb7ffba Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repro-needed Issues that cannot be reproduced or miss proper descriptive examples.
Projects
None yet
Development

No branches or pull requests

3 participants