Frontend: Avoid retypechecking the right hand side of assignment operators

This commit is contained in:
Steven Schäfer
2019-10-31 13:11:48 +01:00
committed by Mikhail Glukhikh
parent 41c81d25a0
commit ab506c1579
6 changed files with 44 additions and 1 deletions
@@ -9763,6 +9763,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt");
}
@TestMetadata("genericAssignmentOperator.kt")
public void testGenericAssignmentOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
}
@TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.kt");
@@ -29,7 +29,9 @@ import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingContextUtils;
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace;
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.calls.context.CallPosition;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
@@ -37,7 +39,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
@@ -213,6 +214,12 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.trace.report(UNRESOLVED_REFERENCE.on(operationSign, operationSign));
temporary.commit();
return rightInfo.clearType();
} else if (ArgumentTypeResolver.getFunctionLiteralArgumentIfAny(right, context) == null &&
ArgumentTypeResolver.getCallableReferenceExpressionIfAny(right, context) == null) {
// Cache the type info for the right hand side so that we don't evaluate it twice if there is no valid plusAssign.
// We skip over function literals and references, since ArgumentTypeResolver will only resolve the shape of the
// function type before attempting to resolve the call.
facade.getTypeInfo(right, context.replaceContextDependency(ContextDependency.DEPENDENT));
}
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(left, leftType, context.trace.getBindingContext());
@@ -0,0 +1,9 @@
class R<T>
fun <T> f(): R<T> = R<T>()
operator fun Int.plusAssign(<!UNUSED_PARAMETER!>y<!>: R<Int>) {}
fun box() {
1 += f()
}
@@ -0,0 +1,12 @@
package
public fun box(): kotlin.Unit
public fun </*0*/ T> f(): R<T>
public operator fun kotlin.Int.plusAssign(/*0*/ y: R<kotlin.Int>): kotlin.Unit
public final class R</*0*/ T> {
public constructor R</*0*/ T>()
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
}
@@ -9770,6 +9770,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt");
}
@TestMetadata("genericAssignmentOperator.kt")
public void testGenericAssignmentOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
}
@TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.kt");
@@ -9765,6 +9765,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt");
}
@TestMetadata("genericAssignmentOperator.kt")
public void testGenericAssignmentOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
}
@TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/hasErrorInConstrainingTypes.kt");