You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make UnsafeCast rule less aggressive so it only flags usage of the "unsafe" cast operator when the cast is known to fail:
val something:String=3asStringval somethingElse:String?=3as?String
but do not flag usage of the operator when there's not enough information for the compiler to be sure at compile time that the case will fail.
Context
With type and symbol resolution we can flag usage of the "unsafe" cast operator when we know at compile time that the cast will fail, but ignore usage of the operator when it only might fail to avoid false positives.
There are some redundant usages of the "safe" cast operator within detekt that can't currently be changed to the "unsafe" operator without flagging UnsafeCast even when it would be OK, like:
// safe cast to KtValueArgument not necessary since type was already checked
parent isKtValueArgument&& (parent as?KtValueArgument)?.isNamed() ==true
// PomTransaction is a subclass of PomTransactionBase so "unsafe" cast is safeoverridefunrunTransaction(transaction:PomTransaction) {
(transaction as?PomTransactionBase)?.run()
}
// docs say "project.version" returns a string and is never null, so safe cast not neededoverride= (project.version as?String)?.endsWith("-SNAPSHOT") ==true
Changing it to be less aggressive and match behavior of the compiler would help with this.
The text was updated successfully, but these errors were encountered:
3flex
changed the title
UnsafeCast - loose & strict mode
Make UnsafeCast less aggressive
Apr 20, 2019
@arturbosch I'm happy to work on this one but want to check first that you're ok with this approach since it will also reduce the positive detection rate. I think it's better to reduce false positives as much as possible even if the rule starts to miss some real issues. Thoughts?
Expected Behavior of the rule
Make UnsafeCast rule less aggressive so it only flags usage of the "unsafe" cast operator when the cast is known to fail:
but do not flag usage of the operator when there's not enough information for the compiler to be sure at compile time that the case will fail.
Context
With type and symbol resolution we can flag usage of the "unsafe" cast operator when we know at compile time that the cast will fail, but ignore usage of the operator when it only might fail to avoid false positives.
There are some redundant usages of the "safe" cast operator within detekt that can't currently be changed to the "unsafe" operator without flagging UnsafeCast even when it would be OK, like:
Changing it to be less aggressive and match behavior of the compiler would help with this.
The text was updated successfully, but these errors were encountered: