diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 079a6e9f74b..881c52253f0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -199,7 +199,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { compileTimeConstant != null ? ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue() : null; boolean hasError = constantChecker.checkConstantExpressionType(constantValue, expression, context.expectedType); if (hasError) { - return TypeInfoFactoryKt.createTypeInfo(getDefaultType(elementType), context); + return TypeInfoFactoryKt.createTypeInfo(constantValue != null ? constantValue.getType() : getDefaultType(elementType), + context); } } diff --git a/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt new file mode 100644 index 00000000000..5cf2305b739 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Int'" "true" + +fun foo() { + val x: Short = 100000 +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt.after b/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt.after new file mode 100644 index 00000000000..7b7ccd94d83 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt.after @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Int'" "true" + +fun foo() { + val x: Int = 100000 +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt new file mode 100644 index 00000000000..46e57f7bb5d --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Long'" "true" + +fun foo() { + val x: Double = 0L +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt.after b/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt.after new file mode 100644 index 00000000000..f8755845879 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt.after @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Long'" "true" + +fun foo() { + val x: Long = 0L +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt new file mode 100644 index 00000000000..68314be4e16 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Long'" "true" + +fun foo() { + val x: Int = 0L +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt.after b/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt.after new file mode 100644 index 00000000000..f8755845879 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt.after @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Long'" "true" + +fun foo() { + val x: Long = 0L +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt new file mode 100644 index 00000000000..decc6425564 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Int'" "true" + +fun foo() { + val x: Byte = 1000 +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt.after b/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt.after new file mode 100644 index 00000000000..79d0cc77ea1 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt.after @@ -0,0 +1,5 @@ +// "Change 'x' type to 'Int'" "true" + +fun foo() { + val x: Int = 1000 +} \ 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 e755ba41a84..de005f6bfef 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -7741,6 +7741,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("intToShortTypeMismatch.kt") + public void testIntToShortTypeMismatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/intToShortTypeMismatch.kt"); + doTest(fileName); + } + @TestMetadata("letClassImplementAdditionalInterface.kt") public void testLetClassImplementAdditionalInterface() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/letClassImplementAdditionalInterface.kt"); @@ -7819,6 +7825,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("longToDoubleTypeMismatch.kt") + public void testLongToDoubleTypeMismatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/longToDoubleTypeMismatch.kt"); + doTest(fileName); + } + + @TestMetadata("longToIntTypeMismatch.kt") + public void testLongToIntTypeMismatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/longToIntTypeMismatch.kt"); + doTest(fileName); + } + @TestMetadata("makeReturnTypeNullable.kt") public void testMakeReturnTypeNullable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/makeReturnTypeNullable.kt"); @@ -7861,6 +7879,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("shortToByteTypeMismatch.kt") + public void testShortToByteTypeMismatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/shortToByteTypeMismatch.kt"); + doTest(fileName); + } + @TestMetadata("tooManyArgumentsException.kt") public void testTooManyArgumentsException() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/tooManyArgumentsException.kt");