[FE 1.0] Report INTEGER_OPERATOR_RESOLVE_WILL_CHANGE in missing cases

Covered places:
- local properties
- vars
- return positions of functions and lambdas

^KT-45970 Fixed
^KT-55358 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-12-08 17:43:54 +02:00
committed by Space Team
parent a979960e63
commit bd3a28d04d
15 changed files with 161 additions and 21 deletions
@@ -2988,6 +2988,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@Test
@TestMetadata("referenceInCycleInProperties.kt")
public void testReferenceInCycleInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceInCycleInProperties.kt");
}
@Test
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
@@ -22260,6 +22266,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.kt");
}
@Test
@TestMetadata("integerLiteralWillChangeResolveInFunctionReturnPosition.kt")
public void testIntegerLiteralWillChangeResolveInFunctionReturnPosition() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/integerLiteralWillChangeResolveInFunctionReturnPosition.kt");
}
@Test
@TestMetadata("kt41679.kt")
public void testKt41679() throws Exception {
@@ -2994,6 +2994,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@Test
@TestMetadata("referenceInCycleInProperties.kt")
public void testReferenceInCycleInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceInCycleInProperties.kt");
}
@Test
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
@@ -22266,6 +22272,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.kt");
}
@Test
@TestMetadata("integerLiteralWillChangeResolveInFunctionReturnPosition.kt")
public void testIntegerLiteralWillChangeResolveInFunctionReturnPosition() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/integerLiteralWillChangeResolveInFunctionReturnPosition.kt");
}
@Test
@TestMetadata("kt41679.kt")
public void testKt41679() throws Exception {
@@ -2988,6 +2988,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@Test
@TestMetadata("referenceInCycleInProperties.kt")
public void testReferenceInCycleInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceInCycleInProperties.kt");
}
@Test
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
@@ -22260,6 +22266,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.kt");
}
@Test
@TestMetadata("integerLiteralWillChangeResolveInFunctionReturnPosition.kt")
public void testIntegerLiteralWillChangeResolveInFunctionReturnPosition() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/integerLiteralWillChangeResolveInFunctionReturnPosition.kt");
}
@Test
@TestMetadata("kt41679.kt")
public void testKt41679() throws Exception {
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtVariableDeclaration
import org.jetbrains.kotlin.resolve.DescriptorResolver.transformAnonymousTypeIfNeeded
import org.jetbrains.kotlin.resolve.calls.checkers.NewSchemeOfIntegerOperatorResolutionChecker
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
@@ -128,12 +127,6 @@ class VariableTypeAndInitializerResolver(
val initializer = variable.initializer
val initializerType =
expressionTypingServices.safeGetType(scope, initializer!!, variableType, dataFlowInfo, inferenceSession, trace)
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(
variableType,
initializer,
trace,
constantExpressionEvaluator.module
)
val constant = constantExpressionEvaluator.evaluateExpression(initializer, trace, initializerType)
?: return@computeInitializer null
@@ -36,7 +36,7 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker {
} else {
valueParameter.type
}.unwrap().lowerIfFlexible()
if (!expectedType.isPrimitiveNumberOrNullableType()) {
if (!needToCheck(expectedType)) {
continue
}
for (argument in arguments.arguments) {
@@ -53,12 +53,16 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker {
trace: BindingTrace,
moduleDescriptor: ModuleDescriptor
) {
val type = expectedType.lowerIfFlexible()
if (type.isPrimitiveNumberOrNullableType()) {
checkArgumentImpl(type, KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor)
if (needToCheck(expectedType)) {
checkArgumentImpl(expectedType.lowerIfFlexible(), KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor)
}
}
fun needToCheck(expectedType: KotlinType): Boolean {
if (TypeUtils.noExpectedType(expectedType)) return false
return expectedType.lowerIfFlexible().isPrimitiveNumberOrNullableType()
}
private fun checkArgumentImpl(
expectedType: SimpleType,
argumentExpression: KtExpression,
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.checkers.NewSchemeOfIntegerOperatorResolutionChecker
import org.jetbrains.kotlin.resolve.calls.commonSuperType
import org.jetbrains.kotlin.resolve.calls.components.*
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
@@ -365,13 +366,17 @@ class ResolvedAtomCompleter(
.replaceBindingTrace(topLevelTrace)
val argumentExpression = resultValueArgument.valueArgument.getArgumentExpression() ?: continue
kotlinToResolvedCallTransformer.updateRecordedType(
val updatedType = kotlinToResolvedCallTransformer.updateRecordedType(
argumentExpression,
parameter = null,
context = newContext,
reportErrorForTypeMismatch = true,
convertedArgumentType = null
)
if (updatedType != null) {
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(updatedType, argumentExpression, topLevelTrace, moduleDescriptor)
}
}
}
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker;
import org.jetbrains.kotlin.resolve.calls.checkers.NewSchemeOfIntegerOperatorResolutionChecker;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession;
import org.jetbrains.kotlin.resolve.calls.smartcasts.*;
@@ -447,6 +448,8 @@ public class DataFlowAnalyzer {
expressionType = ((TypedCompileTimeConstant<?>) value).getType();
}
NewSchemeOfIntegerOperatorResolutionChecker.checkArgument(context.expectedType, expression, context.trace, module);
return createCheckedTypeInfo(expressionType, context, expression);
}
}
@@ -0,0 +1,16 @@
// FIR_IDENTICAL
// WITH_STDLIB
abstract class Parser {
open fun parseString(x: String): List<Int> = null!!
fun parse(name: String): Int = null!!
fun parse(name: String, content: String): Int = null!!
}
class Some(strings: List<String>) {
val parser = object : Parser() {
override fun parseString(x: String) = listOfInt
}
private val listOfString = strings
private val listOfInt: List<Int> = listOfString.map(parser::parse)
}
@@ -0,0 +1,22 @@
package
public abstract class Parser {
public constructor Parser()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun parse(/*0*/ name: kotlin.String): kotlin.Int
public final fun parse(/*0*/ name: kotlin.String, /*1*/ content: kotlin.String): kotlin.Int
public open fun parseString(/*0*/ x: kotlin.String): kotlin.collections.List<kotlin.Int>
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Some {
public constructor Some(/*0*/ strings: kotlin.collections.List<kotlin.String>)
private final val listOfInt: kotlin.collections.List<kotlin.Int>
private final val listOfString: kotlin.collections.List<kotlin.String>
public final val parser: Parser
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -15,7 +15,7 @@ val a10 = <!DIVISION_BY_ZERO!>1 / 0.0f<!>
val a11 = <!DIVISION_BY_ZERO!>1 / 0.0<!>
val a12 = <!DIVISION_BY_ZERO!>1L / 0<!>
val b1: Byte = <!DIVISION_BY_ZERO, INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 / 0<!>
val b1: Byte = <!DIVISION_BY_ZERO, TYPE_MISMATCH!>1 / 0<!>
@Ann(<!ANNOTATION_ARGUMENT_MUST_BE_CONST, DIVISION_BY_ZERO!>1 / 0<!>) val b2 = 1
annotation class Ann(val i : Int)
@@ -0,0 +1,19 @@
// ISSUE: KT-55358
fun test_0() = 1 + 2
fun test_1(): Byte = <!RETURN_TYPE_MISMATCH!>1 + 2<!>
fun test_2(b: Boolean): Byte {
if (b) return <!RETURN_TYPE_MISMATCH!>1 + 2<!>
return <!RETURN_TYPE_MISMATCH!>3 + 4<!>
}
fun test_4(): Byte = run { <!ARGUMENT_TYPE_MISMATCH!>1 + 2<!> }
fun test_5() = run<Byte> { <!ARGUMENT_TYPE_MISMATCH!>1 + 2<!> }
fun test_6() = runWithByte { <!ARGUMENT_TYPE_MISMATCH, TYPE_MISMATCH!>1 + 2<!> }
fun <R> run(block: () -> R): R = block()
fun runWithByte(block: () -> Byte): Byte = block()
@@ -0,0 +1,19 @@
// ISSUE: KT-55358
fun test_0() = 1 + 2
fun test_1(): Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
fun test_2(b: Boolean): Byte {
if (b) return <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
return <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>3 + 4<!>
}
fun test_4(): Byte = run { <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!> }
fun test_5() = run<Byte> { <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!> }
fun test_6() = runWithByte { <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 + 2<!> }
fun <R> run(block: () -> R): R = block()
fun runWithByte(block: () -> Byte): Byte = block()
@@ -0,0 +1,11 @@
package
public fun </*0*/ R> run(/*0*/ block: () -> R): R
public fun runWithByte(/*0*/ block: () -> kotlin.Byte): kotlin.Byte
public fun test_0(): kotlin.Int
public fun test_1(): kotlin.Byte
public fun test_2(/*0*/ b: kotlin.Boolean): kotlin.Byte
public fun test_4(): kotlin.Byte
public fun test_5(): kotlin.Byte
public fun test_6(): kotlin.Byte
+8 -8
View File
@@ -10,9 +10,9 @@ val d_1: Long = 1
var d_2: Long = 1
val e_1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var e_2: Byte = 1 + 2
var e_2: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val f_1: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var f_2: Short = 1 + 2
var f_2: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val g_1: Int = 1 + 2
var g_2: Int = 1 + 2
val h_1: Long = 1 + 2
@@ -28,10 +28,10 @@ fun local() {
val d_1: Long = 1
var d_2: Long = 1
val e_1: Byte = 1 + 2
var e_2: Byte = 1 + 2
val f_1: Short = 1 + 2
var f_2: Short = 1 + 2
val e_1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var e_2: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val f_1: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var f_2: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val g_1: Int = 1 + 2
var g_2: Int = 1 + 2
val h_1: Long = 1 + 2
@@ -49,9 +49,9 @@ class Member {
var d_2: Long = 1
val e_1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var e_2: Byte = 1 + 2
var e_2: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val f_1: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
var f_2: Short = 1 + 2
var f_2: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>
val g_1: Int = 1 + 2
var g_2: Int = 1 + 2
val h_1: Long = 1 + 2
@@ -2994,6 +2994,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@Test
@TestMetadata("referenceInCycleInProperties.kt")
public void testReferenceInCycleInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceInCycleInProperties.kt");
}
@Test
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
@@ -22266,6 +22272,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.kt");
}
@Test
@TestMetadata("integerLiteralWillChangeResolveInFunctionReturnPosition.kt")
public void testIntegerLiteralWillChangeResolveInFunctionReturnPosition() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/integerLiteralWillChangeResolveInFunctionReturnPosition.kt");
}
@Test
@TestMetadata("kt41679.kt")
public void testKt41679() throws Exception {