Do not suggest cast for SIGNED_CONSTANT_CONVERTED_TO_UNSIGNED
Related to KT-27590
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user