[FE 1.0] Report INTEGER_OPERATOR_RESOLVE_WILL_CHANGE on calls in parenthesis

^KT-47729 In progress
This commit is contained in:
Dmitriy Novozhilov
2021-07-15 13:00:42 +03:00
committed by TeamCityServer
parent ea4ab46765
commit 2fb5f776d8
8 changed files with 85 additions and 5 deletions
@@ -19877,6 +19877,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/numbers/kt47447.kt");
}
@Test
@TestMetadata("kt47729_parenthesis.kt")
public void testKt47729_parenthesis() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt");
}
@Test
@TestMetadata("literalReceiverWithIntegerValueType.kt")
public void testLiteralReceiverWithIntegerValueType() throws Exception {
@@ -19877,6 +19877,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/numbers/kt47447.kt");
}
@Test
@TestMetadata("kt47729_parenthesis.kt")
public void testKt47729_parenthesis() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt");
}
@Test
@TestMetadata("literalReceiverWithIntegerValueType.kt")
public void testLiteralReceiverWithIntegerValueType() throws Exception {
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtConstantExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.psi.KtUnaryExpression
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -33,15 +35,16 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker {
valueParameter.type
}.unwrap().lowerIfFlexible()
for (argument in arguments.arguments) {
val expression = argument.getArgumentExpression() ?: continue
val expression = KtPsiUtil.deparenthesize(argument.getArgumentExpression()) ?: continue
val compileTimeValue =
bindingContext[BindingContext.COMPILE_TIME_VALUE, expression] as? IntegerValueTypeConstant? ?: continue
val callForArgument = expression.getResolvedCall(bindingContext) ?: continue
if (!callForArgument.isIntOperator()) continue
val callElement = callForArgument.call.callElement
if (callElement is KtConstantExpression) continue
if (callElement is KtUnaryExpression) {
val token = callElement.operationToken
val callElement = callForArgument.call.callElement as? KtExpression ?: continue
val deparenthesizedElement = KtPsiUtil.deparenthesize(callElement)!!
if (deparenthesizedElement is KtConstantExpression) continue
if (deparenthesizedElement is KtUnaryExpression) {
val token = deparenthesizedElement.operationToken
if (token == KtTokens.PLUS || token == KtTokens.MINUS) continue
}
@@ -0,0 +1,20 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// ISSUE: Kt-47447, KT-47729
fun takeLong(x: Long) {}
object Foo {
var longProperty: Long = 0
infix fun infixOperator(x: Long) {}
}
// Should be warning in all places
fun test() {
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>)
takeLong((<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>))
Foo.longProperty = 1 + 1
Foo.longProperty = (1 + 1)
Foo infixOperator <!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>
Foo infixOperator (<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>)
}
@@ -0,0 +1,20 @@
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
// ISSUE: Kt-47447, KT-47729
fun takeLong(x: Long) {}
object Foo {
var longProperty: Long = 0
infix fun infixOperator(x: Long) {}
}
// Should be warning in all places
fun test() {
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
takeLong((<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>))
Foo.longProperty = 1 + 1
Foo.longProperty = (1 + 1)
Foo infixOperator <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>
Foo infixOperator (<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
}
@@ -0,0 +1,13 @@
package
public fun takeLong(/*0*/ x: kotlin.Long): kotlin.Unit
public fun test(): kotlin.Unit
public object Foo {
private constructor Foo()
public final var longProperty: kotlin.Long
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 infix fun infixOperator(/*0*/ x: kotlin.Long): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -19883,6 +19883,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/numbers/kt47447.kt");
}
@Test
@TestMetadata("kt47729_parenthesis.kt")
public void testKt47729_parenthesis() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt");
}
@Test
@TestMetadata("literalReceiverWithIntegerValueType.kt")
public void testLiteralReceiverWithIntegerValueType() throws Exception {
@@ -19877,6 +19877,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/numbers/kt47447.kt");
}
@Test
@TestMetadata("kt47729_parenthesis.kt")
public void testKt47729_parenthesis() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt");
}
@Test
@TestMetadata("literalReceiverWithIntegerValueType.kt")
public void testLiteralReceiverWithIntegerValueType() throws Exception {