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

False positives on UnsafeCast on AppVeyor (Windows?) only #1137

Closed
rock3r opened this issue Sep 17, 2018 · 6 comments · Fixed by #1879
Closed

False positives on UnsafeCast on AppVeyor (Windows?) only #1137

rock3r opened this issue Sep 17, 2018 · 6 comments · Fixed by #1879

Comments

@rock3r
Copy link
Contributor

rock3r commented Sep 17, 2018

Steps to Reproduce (for bugs)

See https://github.com/arturbosch/detekt/blob/fab854abc1d1efdc6218dc8e5cf486f6fb194de2/detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/ThresholdedCodeSmellAssert.kt

On *nix (my macOS machine, and on Travis' CI machines) I get no warnings.

On Windows (AppVeyor) we get these warnings:

Ruleset: potential-bugs - 1h debt
	UnsafeCast - [isThresholded] at C:\projects\detekt\detekt-test\src\main\kotlin\io\gitlab\arturbosch\detekt\test\ThresholdedCodeSmellAssert.kt:12:36
	UnsafeCast - [smell] at C:\projects\detekt\detekt-test\src\main\kotlin\io\gitlab\arturbosch\detekt\test\ThresholdedCodeSmellAssert.kt:26:15
	UnsafeCast - [smell] at C:\projects\detekt\detekt-test\src\main\kotlin\io\gitlab\arturbosch\detekt\test\ThresholdedCodeSmellAssert.kt:35:15

The warnings on Windows are incorrect, as those casts are all guarded behind an assertion. Neither the compiler nor the IDE complain about those.

Your Environment

  • Version used: RC9
  • Operating System and version: macOS 10.13.6/Travis CI/AppVeyor
  • Link to your project: Detekt :)
@3flex
Copy link
Member

3flex commented Sep 24, 2018

This has come up previously: #926

@rock3r
Copy link
Contributor Author

rock3r commented Sep 24, 2018

Hm I missed that, sorry. In this case though those are plain false positives...

@3flex
Copy link
Member

3flex commented Sep 24, 2018

Oh sorry, I meant more that the difference in results between *nix and Windows had come up previously (but again with UnsafeCast).

@rock3r
Copy link
Contributor Author

rock3r commented Sep 24, 2018

Ah yeah no problem mate :) I don't know what makes that rule so platform-reliant... Haven't had time to look at the implementation. I plan on doing, but I really have little time these days

@arturbosch
Copy link
Member

arturbosch commented Sep 24, 2018

The implementation just uses a function provided by the kotlin compiler, so I guess we need to track this down on the kotlin side. Thanks for the linking!

@3flex
Copy link
Member

3flex commented Oct 3, 2018

I've looked into this more closely - the current check provided by detekt does not respect smart casts. The compiler's implementation only checks the format of the expression and looks for the as keyword.

To fix this so the check respects smart casts I expect we need type and symbol resolution.

Didn't look into differences between Windows & Linux.

@3flex 3flex added false-positive and removed bug labels Aug 29, 2019
@3flex 3flex self-assigned this Aug 29, 2019
@3flex 3flex removed their assignment Sep 3, 2019
@arturbosch arturbosch added this to the 1.1.0 milestone Sep 14, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants