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

Wrong "second self" force unwrapping violation #2779

Closed
2 tasks done
janmisar opened this issue Jun 4, 2019 · 1 comment
Closed
2 tasks done

Wrong "second self" force unwrapping violation #2779

janmisar opened this issue Jun 4, 2019 · 1 comment

Comments

@janmisar
Copy link

janmisar commented Jun 4, 2019

New Issue Checklist

Describe the bug

button.on { [weak self] _ in
    self?.delegate?.didTapClose(in: self!)
}

This creates force unwrapping warning and it should not. This is safe - when self is nil, second self is not even called so it won't crash.

It used to work great in previous versions. It's broken since 0.33, I guess it could be connected with #2759.

@jpsim
Copy link
Collaborator

jpsim commented Jun 4, 2019

This creates force unwrapping warning and it should not. This is safe - when self is nil, second self is not even called so it won't crash.

Are you sure this is safe? What if the last reference to self is released by a different thread between the time the left self is evaluated and the right self! is evaluated?

It used to work great in previous versions. It's broken since 0.33, I guess it could be connected with #2759.

You have this backwards, a limitation in SwiftLint meant that the force_unwrapping rule wasn't applied to self keywords at all. The behavior you're describing has also applied to identifiers other than self since the rule was originally created: controller?.delegate?.didTapClose(in: controller!)

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

No branches or pull requests

3 participants