diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 2a0137e0ec8..b564e8deb34 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 1e6311ea7bc..66000e29c9c 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt index 2a21d1687d9..1867ce4b3fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt @@ -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 } diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt new file mode 100644 index 00000000000..6fd760f797b --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt @@ -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(1 + 1) + takeLong((1 + 1)) + Foo.longProperty = 1 + 1 + Foo.longProperty = (1 + 1) + Foo infixOperator 1 + 1 + Foo infixOperator (1 + 1) +} diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt new file mode 100644 index 00000000000..e7bd77db908 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt @@ -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(1 + 1) + takeLong((1 + 1)) + Foo.longProperty = 1 + 1 + Foo.longProperty = (1 + 1) + Foo infixOperator 1 + 1 + Foo infixOperator (1 + 1) +} diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.txt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.txt new file mode 100644 index 00000000000..a5afef74c21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.txt @@ -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 +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index f907571d495..369b91952f5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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 { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 8c8232286fc..0e704459e3c 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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 {