Can be replaced with binary operator: do not suggest when receiver or argument is floating point type

#KT-28596 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-02-08 15:10:05 +09:00
committed by Mikhail Glukhikh
parent 48619a49ed
commit d583c1be58
7 changed files with 34 additions and 5 deletions
@@ -25,7 +25,8 @@ fun KtExpression?.getKotlinTypeWithPossibleSmartCastToFP(
bindingContext: BindingContext,
descriptor: DeclarationDescriptor?,
languageVersionSettings: LanguageVersionSettings,
dataFlowValueFactory: DataFlowValueFactory
dataFlowValueFactory: DataFlowValueFactory,
defaultType: (KotlinType, Set<KotlinType>) -> KotlinType = { givenType, _ -> givenType }
): KotlinType? {
val givenType = this?.getKotlinTypeForComparison(bindingContext) ?: return null
@@ -40,13 +41,13 @@ fun KtExpression?.getKotlinTypeWithPossibleSmartCastToFP(
if (descriptor != null) {
val dataFlow = dataFlowValueFactory.createDataFlowValue(this, givenType, bindingContext, descriptor)
val stableTypes = bindingContext.getDataFlowInfoBefore(this).getStableTypes(dataFlow, languageVersionSettings)
stableTypes.firstNotNullResult {
return stableTypes.firstNotNullResult {
when {
KotlinBuiltIns.isDoubleOrNullableDouble(it) -> it
KotlinBuiltIns.isFloatOrNullableFloat(it) -> it
else -> null
}
}?.let { return it }
} ?: defaultType(givenType, stableTypes)
}
return givenType
}