diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt index 62b26c31e01..dd4c3212edf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixFactoryForTypeMismatchError.kt @@ -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)) } diff --git a/idea/testData/quickfix/typeMismatch/casts/unsigned.kt b/idea/testData/quickfix/typeMismatch/casts/unsigned.kt new file mode 100644 index 00000000000..40cd5b5bff6 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/casts/unsigned.kt @@ -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(1) \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 5c8b4146e52..c2f07abc93c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -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")