Do not suggest cast for SIGNED_CONSTANT_CONVERTED_TO_UNSIGNED

Related to KT-27590
This commit is contained in:
Mikhail Glukhikh
2018-12-19 18:47:26 +03:00
parent d7ce79cc76
commit 73b6148407
3 changed files with 20 additions and 1 deletions
@@ -159,7 +159,10 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() {
}
// We don't want to cast a cast or type-asserted expression:
if (diagnosticElement !is KtBinaryExpressionWithTypeRHS && diagnosticElement.parent !is KtBinaryExpressionWithTypeRHS) {
if (diagnostic.factory != Errors.SIGNED_CONSTANT_CONVERTED_TO_UNSIGNED &&
diagnosticElement !is KtBinaryExpressionWithTypeRHS &&
diagnosticElement.parent !is KtBinaryExpressionWithTypeRHS
) {
actions.add(CastExpressionFix(diagnosticElement.getTopMostQualifiedForSelectorIfAny(), expectedType))
}
+11
View File
@@ -0,0 +1,11 @@
// "Cast expression '1' to 'UInt'" "false"
// WITH_RUNTIME
// ERROR: Conversion of signed constants to unsigned ones is prohibited
// ACTION: Change parameter 'u' type of function 'takeUInt' to 'Int'
// ACTION: Convert property initializer to getter
// ACTION: Do not show hints for current method
// ACTION: Add 'u =' to argument
fun takeUInt(u: UInt) = 0
val b = takeUInt(<caret>1)
@@ -12308,6 +12308,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
public void testTypeMismatchLongNameRuntime() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/casts/typeMismatchLongNameRuntime.kt");
}
@TestMetadata("unsigned.kt")
public void testUnsigned() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/casts/unsigned.kt");
}
}
@TestMetadata("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch")