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

Comments

Projects
None yet
3 participants
@ldiqual

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

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Jul 26, 2017

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.
Collaborator

marcelofabri commented Jul 26, 2017

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

This comment has been minimized.

Show comment
Hide comment
@otaviolima

otaviolima Jul 26, 2017

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Jul 26, 2017

Collaborator

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).

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 in fb7ffba Aug 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment