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 3cf78b35161..d40b993e38b 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 @@ -25050,6 +25050,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.kt"); } + @Test + @TestMetadata("kt28109.kt") + public void testKt28109() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/kt28109.kt"); + } + @Test @TestMetadata("kt36264.kt") public void testKt36264() 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 009b6726269..ead36887f9a 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 @@ -25050,6 +25050,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.kt"); } + @Test + @TestMetadata("kt28109.kt") + public void testKt28109() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/kt28109.kt"); + } + @Test @TestMetadata("kt36264.kt") public void testKt36264() throws Exception { 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 29b44c3ada1..0f7d207c0d3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -760,15 +760,22 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return typeInfo.clearType(); } + KtExpression deparenthesizedBaseExpression = KtPsiUtil.deparenthesize(baseExpression); + // a[i]++/-- takes special treatment because it is actually let j = i, arr = a in arr.set(j, a.get(j).inc()) if ((operationType == KtTokens.PLUSPLUS || operationType == KtTokens.MINUSMINUS) && - baseExpression instanceof KtArrayAccessExpression) { + deparenthesizedBaseExpression instanceof KtArrayAccessExpression) { KtExpression stubExpression = ExpressionTypingUtils.createFakeExpressionOfType( baseExpression.getProject(), context.trace, "e", type); TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create( context.trace, "trace to resolve array access set method for unary expression", expression); ExpressionTypingContext newContext = context.replaceBindingTrace(temporaryBindingTrace); - resolveImplicitArrayAccessSetMethod((KtArrayAccessExpression) baseExpression, stubExpression, newContext, context.trace); + resolveImplicitArrayAccessSetMethod( + (KtArrayAccessExpression) deparenthesizedBaseExpression, + stubExpression, + newContext, + context.trace + ); } // Resolve the operation reference diff --git a/compiler/testData/diagnostics/tests/resolve/kt28109.fir.kt b/compiler/testData/diagnostics/tests/resolve/kt28109.fir.kt new file mode 100644 index 00000000000..ca66d8769dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/kt28109.fir.kt @@ -0,0 +1,11 @@ +// WITH_STDLIB + +class Cell { + operator fun get(s: Int) = 1 +} + +fun box(): String { + val c = Cell() + (c[0])++ + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/resolve/kt28109.kt b/compiler/testData/diagnostics/tests/resolve/kt28109.kt new file mode 100644 index 00000000000..94fb752b60a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/kt28109.kt @@ -0,0 +1,11 @@ +// WITH_STDLIB + +class Cell { + operator fun get(s: Int) = 1 +} + +fun box(): String { + val c = Cell() + (c[0])++ + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/kt28109.txt b/compiler/testData/diagnostics/tests/resolve/kt28109.txt new file mode 100644 index 00000000000..daa3baafa26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/kt28109.txt @@ -0,0 +1,11 @@ +package + +public fun box(): kotlin.String + +public final class Cell { + public constructor Cell() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun get(/*0*/ s: kotlin.Int): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + 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 1db5d44e7e4..5b82e83e073 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 @@ -25062,6 +25062,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/resolve/inferenceInLinkedLambdasDependentOnExpectedType.kt"); } + @Test + @TestMetadata("kt28109.kt") + public void testKt28109() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/kt28109.kt"); + } + @Test @TestMetadata("kt36264.kt") public void testKt36264() throws Exception {