Skip to content

Trust Kotlin compiler to identify unsafe casts #1879

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

Merged
merged 6 commits into from
Sep 14, 2019
Merged

Conversation

3flex
Copy link
Member

@3flex 3flex commented Aug 31, 2019

UnsafeCast now trusts the Kotlin compiler to identify casts that won't succeed. This should eliminate false positives though the detection rate for actual issues will drop, as some "safe" casts that the compiler cannot always tell will fail may still cause problems.

Now requires type/symbol resolution enabled in the detekt run for the rule to work.

Fixes #1601
Fixes #1137 (I couldn't replicate the original issue by just removing the suppression lines in ThresholdedCodeSmellAssert and rerunning CI in AppVeyor, though this should resolve it anyway).

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This PR contains some nice improvements and refactorings.

@3flex
Copy link
Member Author

3flex commented Sep 2, 2019

Blocked by #1880

@3flex 3flex added the blocked label Sep 2, 2019
@arturbosch arturbosch added this to the 1.1.0 milestone Sep 12, 2019
@codecov-io
Copy link

codecov-io commented Sep 14, 2019

Codecov Report

Merging #1879 into master will decrease coverage by <.01%.
The diff coverage is 51.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1879      +/-   ##
============================================
- Coverage     80.45%   80.44%   -0.01%     
- Complexity     1968     1969       +1     
============================================
  Files           326      326              
  Lines          5510     5513       +3     
  Branches       1022     1019       -3     
============================================
+ Hits           4433     4435       +2     
  Misses          543      543              
- Partials        534      535       +1
Impacted Files Coverage Δ Complexity Δ
...turbosch/detekt/rules/KtClassOrObjectExtensions.kt 66.66% <ø> (-8.34%) 0 <0> (ø)
...gitlab/arturbosch/detekt/rules/style/MayBeConst.kt 75% <0%> (-2.28%) 40 <2> (-1)
...rturbosch/detekt/rules/style/UnusedPrivateClass.kt 67.85% <0%> (ø) 4 <0> (ø) ⬇️
...bosch/detekt/rules/bugs/EqualsWithHashCodeExist.kt 89.47% <0%> (+3.75%) 9 <3> (ø) ⬇️
...turbosch/detekt/rules/style/UnusedPrivateMember.kt 93.47% <100%> (-0.08%) 5 <0> (ø)
...itlab/arturbosch/detekt/rules/style/ReturnCount.kt 87.75% <100%> (+2.04%) 20 <0> (ø) ⬇️
...etekt/rules/style/FunctionOnlyReturningConstant.kt 92% <100%> (-0.31%) 27 <0> (-1)
...sch/detekt/rules/naming/MatchingDeclarationName.kt 92.85% <100%> (+7.14%) 7 <0> (ø) ⬇️
.../gitlab/arturbosch/detekt/rules/bugs/UnsafeCast.kt 75% <40%> (-13.89%) 4 <1> (-1)
...sch/detekt/rules/style/UnnecessaryAbstractClass.kt 91.17% <50%> (+2.28%) 15 <0> (ø) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f714f6e...2236d2d. Read the comment docs.

@3flex 3flex merged commit bd1ba08 into detekt:master Sep 14, 2019
@3flex 3flex deleted the 1601-fix branch September 14, 2019 06:17
sowmyav24 pushed a commit to sowmyav24/detekt that referenced this pull request Sep 17, 2019
* Trust Kotlin compiler to identify unsafe casts

* Remove unnecessary suppressions

* Remove consecutive lines

* Remove some "safe" calls

* Remove unused import
sowmyav24 pushed a commit to sowmyav24/detekt that referenced this pull request Sep 17, 2019
* Trust Kotlin compiler to identify unsafe casts

* Remove unnecessary suppressions

* Remove consecutive lines

* Remove some "safe" calls

* Remove unused import
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
* Trust Kotlin compiler to identify unsafe casts

* Remove unnecessary suppressions

* Remove consecutive lines

* Remove some "safe" calls

* Remove unused import
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
* Trust Kotlin compiler to identify unsafe casts

* Remove unnecessary suppressions

* Remove consecutive lines

* Remove some "safe" calls

* Remove unused import
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

Successfully merging this pull request may close these issues.

Make UnsafeCast less aggressive False positives on UnsafeCast on AppVeyor (Windows?) only
4 participants