From c3b8f3e8597d0dd97eee303854213bad36533177 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Thu, 13 May 2021 17:06:04 +0300 Subject: [PATCH] [FIR] Add lValueTypeRef to FirVariableAssignment, fix tests with ASSIGNMENT_TYPE_MISMATCH --- .../testData/resolve/settersGetters.kt | 2 +- .../resolveWithStdlib/hashSet.fir.txt | 2 +- .../fir/analysis/checkers/FirHelpers.kt | 32 ++++++++++++------- .../FirInitializerTypeMismatchChecker.kt | 2 +- .../FirAssignmentTypeMismatchChecker.kt | 11 ++----- .../diagnostics/FirDefaultErrorMessages.kt | 16 ++++++++-- .../kotlin/fir/builder/BaseFirBuilder.kt | 1 - .../fir/resolve/inference/FirCallCompleter.kt | 6 ++++ ...rCallCompletionResultsWriterTransformer.kt | 24 ++++++++++---- .../FirExpressionsResolveTransformer.kt | 3 +- .../fir/expressions/FirVariableAssignment.kt | 4 +++ .../builder/FirVariableAssignmentBuilder.kt | 2 ++ .../impl/FirVariableAssignmentImpl.kt | 9 ++++++ .../generator/ImplementationConfigurator.kt | 9 ++++++ .../fir/tree/generator/NodeConfigurator.kt | 1 + .../diagnostics/tests/Properties.fir.kt | 4 +-- .../nullabilityWarnings/dataFlowInfo.fir.kt | 6 ++-- .../nullabilityWarnings/passToJava.fir.kt | 10 +++--- .../platformTypes/rawTypes/arrays.fir.kt | 2 +- .../rawTypes/nonTrivialErasure.fir.kt | 2 +- .../tests/regressions/kt251.fir.kt | 2 +- .../introduction-1/p-6/neg/2.2.fir.kt | 2 +- .../diagnostics/KtFirDataClassConverters.kt | 12 +++---- .../DifferentMavenStdlibVersionInspection.kt | 4 +-- idea/testData/checker/IncDec.fir.kt | 24 +++++++------- idea/testData/checker/Properties.fir.kt | 2 +- idea/testData/checker/regression/kt251.fir.kt | 2 +- .../varianceChanged/fir-build.log | 18 ----------- 28 files changed, 127 insertions(+), 87 deletions(-) delete mode 100644 jps-plugin/testData/incremental/classHierarchyAffected/varianceChanged/fir-build.log diff --git a/compiler/fir/analysis-tests/testData/resolve/settersGetters.kt b/compiler/fir/analysis-tests/testData/resolve/settersGetters.kt index 76a3a26ecca..cd4a461e123 100644 --- a/compiler/fir/analysis-tests/testData/resolve/settersGetters.kt +++ b/compiler/fir/analysis-tests/testData/resolve/settersGetters.kt @@ -2,7 +2,7 @@ class SomeClass { var foo: Int = 0 set(value: String){ - field = value + field = value } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.fir.txt index 6533237f756..31c0a3ce0b4 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashSet.fir.txt @@ -18,5 +18,5 @@ FILE: hashSet.kt public final fun foo(): R|kotlin/Unit| { lvar c: R|kotlin/collections/MutableSet?| = Null(null) R|/c| = R|java/util/HashSet.HashSet||>() - R|/c|!!.R|/d| = R|/produce|() + R|/c|!!.R|/d| = R|/produce|() } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 72577d2c92f..a8c72f8bc1c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.overrideModifier import org.jetbrains.kotlin.fir.analysis.diagnostics.visibilityModifier import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock @@ -521,16 +522,34 @@ private val FirSimpleFunction.matchesToStringSignature: Boolean get() = valueParameters.isEmpty() fun checkTypeMismatch( - lValueType: ConeKotlinType, + lValueOriginalType: ConeKotlinType, rValue: FirExpression, context: CheckerContext, source: FirSourceElement, reporter: DiagnosticReporter, isInitializer: Boolean ) { - val rValueType = rValue.typeRef.coneType + var lValueType = lValueOriginalType + var rValueType = rValue.typeRef.coneType val typeContext = context.session.typeContext + val diagnosticFactory = when { + isInitializer -> { + FirErrors.INITIALIZER_TYPE_MISMATCH + } + source.kind is FirFakeSourceElementKind.DesugaredIncrementOrDecrement -> { + if (!lValueType.isNullable && rValueType.isNullable) { + val tempType = rValueType + rValueType = lValueType + lValueType = tempType + } + FirErrors.RESULT_TYPE_MISMATCH + } + else -> { + FirErrors.ASSIGNMENT_TYPE_MISMATCH + } + } + if (!isSubtypeForTypeMismatch(typeContext, subtype = rValueType, supertype = lValueType)) { if (rValueType is ConeClassLikeType && rValueType.lookupTag.classId == StandardClassIds.Int && @@ -548,15 +567,6 @@ fun checkTypeMismatch( if (rValue.isNullLiteral && lValueType.nullability == ConeNullability.NOT_NULL) { reporter.reportOn(rValue.source, FirErrors.NULL_FOR_NONNULL_TYPE, context) } else { - val diagnosticFactory = when { - isInitializer -> - FirErrors.INITIALIZER_TYPE_MISMATCH - source.kind is FirFakeSourceElementKind.DesugaredIncrementOrDecrement -> - FirErrors.RESULT_TYPE_MISMATCH - else -> - FirErrors.ASSIGNMENT_TYPE_MISMATCH - } - reporter.report(diagnosticFactory.on(source, lValueType, rValueType), context) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt index eed99e0e473..d92b38413e6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirInitializerTypeMismatchChecker.kt @@ -9,9 +9,9 @@ import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.fir.FirRealSourceElementKind import org.jetbrains.kotlin.fir.analysis.checkers.checkTypeMismatch import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext -import org.jetbrains.kotlin.fir.analysis.checkers.isComponentCall import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.declarations.FirProperty +import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.types.coneType object FirInitializerTypeMismatchChecker : FirPropertyChecker() { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt index d37ef1c7aec..bddcb3e6f51 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirAssignmentTypeMismatchChecker.kt @@ -9,17 +9,12 @@ import org.jetbrains.kotlin.fir.analysis.checkers.checkTypeMismatch import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment -import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference -import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.coneType object FirAssignmentTypeMismatchChecker : FirVariableAssignmentChecker() { override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) { val source = expression.rValue.source ?: return - val lValueType = - ((expression.lValue as? FirResolvedNamedReference)?.resolvedSymbol as? FirPropertySymbol)?.fir?.returnTypeRef?.coneType - ?: return - - checkTypeMismatch(lValueType, expression.rValue, context, source, reporter, false) + val coneType = expression.lValueTypeRef.coneType + checkTypeMismatch(coneType, expression.rValue, context, source, reporter, false) } -} \ No newline at end of file +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index c0b9ee2a484..97ecd18e4ef 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -43,6 +43,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ARGUMENT_PASSED_T import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ARGUMENT_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ASSIGNED_VALUE_IS_NEVER_READ +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ASSIGNMENT_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ASSIGN_OPERATOR_AMBIGUITY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BACKING_FIELD_IN_INTERFACE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER @@ -248,6 +249,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REIFIED_TYPE_PARA import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_BOUND import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESERVED_MEMBER_INSIDE_INLINE_CLASS +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESULT_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_NOT_ALLOWED import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_TYPE_MISMATCH @@ -522,7 +524,14 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { map.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", TO_STRING) map.put(MANY_LAMBDA_EXPRESSION_ARGUMENTS, "Only one lambda expression is allowed outside a parenthesized argument list") - map.put(ARGUMENT_TYPE_MISMATCH, "Argument type mismatch: actual type is {1} but {0} was expected", TO_STRING, TO_STRING) + map.put(ARGUMENT_TYPE_MISMATCH, "Argument type mismatch: actual type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE) + map.put(ASSIGNMENT_TYPE_MISMATCH, "Assignment type mismatch: actual type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE) + map.put( + RESULT_TYPE_MISMATCH, + "Function return type mismatch: actual type is {1} but {0} was expected", + RENDER_TYPE, + RENDER_TYPE + ) // Ambiguity map.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity between candidates: {0}", SYMBOLS) @@ -834,7 +843,10 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { ) map.put(INITIALIZER_TYPE_MISMATCH, "Initializer type mismatch: expected {0}, actual {1}", RENDER_TYPE, RENDER_TYPE) map.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility") - map.put(SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, "Setter visibility must be the same or less permissive than property visibility") + map.put( + SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, + "Setter visibility must be the same or less permissive than property visibility" + ) map.put(WRONG_SETTER_RETURN_TYPE, "Setter return type must be Unit") map.put( WRONG_GETTER_RETURN_TYPE, diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index bd14ee924be..5326344fa19 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -469,7 +469,6 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte if (unwrappedArgument == null) { return buildErrorExpression { - source = unwrappedArgument diagnostic = ConeSimpleDiagnostic("Inc/dec without operand", DiagnosticKind.Syntax) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt index 655a635765a..59d3d85f33a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirResolvable import org.jetbrains.kotlin.fir.expressions.FirStatement +import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.resolve.ResolutionMode import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate @@ -56,7 +57,12 @@ class FirCallCompleter( where T : FirResolvable, T : FirStatement { val typeRef = components.typeFromCallee(call) + if (call is FirVariableAssignment) { + call.replaceLValueTypeRef(typeRef) + } + val reference = call.calleeReference as? FirNamedReferenceWithCandidate ?: return CompletionResult(call, true) + val candidate = reference.candidate val initialType = components.initialTypeOfCandidate(candidate, call) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 80621b1cfc6..600c9dded93 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -66,7 +66,7 @@ class FirCallCompletionResultsWriterTransformer( } } - private fun prepareQualifiedTransform( + private fun prepareQualifiedTransform( qualifiedAccessExpression: T, calleeReference: FirNamedReferenceWithCandidate ): T { val subCandidate = calleeReference.candidate @@ -111,7 +111,13 @@ class FirCallCompletionResultsWriterTransformer( ) .transformDispatchReceiver(StoreReceiver, subCandidate.dispatchReceiverExpression()) .transformExtensionReceiver(StoreReceiver, subCandidate.extensionReceiverExpression()) as T - result.replaceTypeRef(typeRef) + + if (result is FirQualifiedAccessExpression) { + result.replaceTypeRef(typeRef) + } else if (result is FirVariableAssignment) { + result.replaceLValueTypeRef(typeRef) + } + if (declaration !is FirErrorFunction) { result.replaceTypeArguments(typeArguments) } @@ -354,13 +360,19 @@ class FirCallCompletionResultsWriterTransformer( ): FirStatement { val calleeReference = variableAssignment.calleeReference as? FirNamedReferenceWithCandidate ?: return variableAssignment - val typeArguments = computeTypeArguments(variableAssignment, calleeReference.candidate) + + // Initialize lValueTypeRef + val qualifiedTransform = prepareQualifiedTransform(variableAssignment, calleeReference) + val lValueTypeRef = qualifiedTransform.lValueTypeRef as FirResolvedTypeRef + val resultLValueType = lValueTypeRef.substituteTypeRef(calleeReference.candidate) + resultLValueType.ensureResolvedTypeDeclaration(session) + variableAssignment.replaceLValueTypeRef(resultLValueType) + session.lookupTracker?.recordTypeResolveAsLookup(resultLValueType, variableAssignment.lValue.source, null) + return variableAssignment.transformCalleeReference( StoreCalleeReference, calleeReference.toResolvedReference(), - ).apply { - replaceTypeArguments(typeArguments) - } + ) } private inner class TypeUpdaterForDelegateArguments : FirTransformer() { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index a76c9f64ff9..817cc45f796 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -677,8 +677,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform val resolvedAssignment = callResolver.resolveVariableAccessAndSelectCandidate(variableAssignment) val result = if (resolvedAssignment is FirVariableAssignment) { val completeAssignment = callCompleter.completeCall(resolvedAssignment, noExpectedType).result // TODO: check - val expectedType = components.typeFromCallee(completeAssignment) - completeAssignment.transformRValue(transformer, withExpectedType(expectedType)) + completeAssignment.transformRValue(transformer, withExpectedType(variableAssignment.lValueTypeRef)) } else { // This can happen in erroneous code only resolvedAssignment diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirVariableAssignment.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirVariableAssignment.kt index 013af30b73e..597830e9ad7 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirVariableAssignment.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirVariableAssignment.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirPureAbstractElement import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.FirImplementationDetail @@ -27,6 +28,7 @@ abstract class FirVariableAssignment : FirPureAbstractElement(), FirQualifiedAcc abstract override val extensionReceiver: FirExpression abstract override val source: FirSourceElement? abstract val lValue: FirReference + abstract val lValueTypeRef: FirTypeRef abstract val rValue: FirExpression override fun accept(visitor: FirVisitor, data: D): R = visitor.visitVariableAssignment(this, data) @@ -44,6 +46,8 @@ abstract class FirVariableAssignment : FirPureAbstractElement(), FirQualifiedAcc @FirImplementationDetail abstract override fun replaceSource(newSource: FirSourceElement?) + abstract fun replaceLValueTypeRef(newLValueTypeRef: FirTypeRef) + abstract override fun transformCalleeReference(transformer: FirTransformer, data: D): FirVariableAssignment abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirVariableAssignment diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirVariableAssignmentBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirVariableAssignmentBuilder.kt index 85a1d99b6ba..f78e64b9516 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirVariableAssignmentBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirVariableAssignmentBuilder.kt @@ -18,6 +18,8 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.expressions.impl.FirVariableAssignmentImpl import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl import org.jetbrains.kotlin.fir.visitors.* /* diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirVariableAssignmentImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirVariableAssignmentImpl.kt index 7700ff9c290..99437bc949b 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirVariableAssignmentImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirVariableAssignmentImpl.kt @@ -11,6 +11,8 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.fir.FirImplementationDetail @@ -34,6 +36,7 @@ internal class FirVariableAssignmentImpl( set(value) { calleeReference = value } + override var lValueTypeRef: FirTypeRef = FirImplicitTypeRefImpl(null) override fun acceptChildren(visitor: FirVisitor, data: D) { calleeReference.accept(visitor, data) @@ -46,6 +49,7 @@ internal class FirVariableAssignmentImpl( if (extensionReceiver !== explicitReceiver && extensionReceiver !== dispatchReceiver) { extensionReceiver.accept(visitor, data) } + lValueTypeRef.accept(visitor, data) rValue.accept(visitor, data) } @@ -60,6 +64,7 @@ internal class FirVariableAssignmentImpl( if (extensionReceiver !== explicitReceiver && extensionReceiver !== dispatchReceiver) { extensionReceiver = extensionReceiver.transform(transformer, data) } + lValueTypeRef = lValueTypeRef.transform(transformer, data) transformRValue(transformer, data) return this } @@ -116,4 +121,8 @@ internal class FirVariableAssignmentImpl( override fun replaceSource(newSource: FirSourceElement?) { source = newSource } + + override fun replaceLValueTypeRef(newLValueTypeRef: FirTypeRef) { + lValueTypeRef = newLValueTypeRef + } } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 7681915f965..935edf0f0ad 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -495,5 +495,14 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() default(it, "FirImplicitTypeRefImpl(null)") useTypes(implicitTypeRefType) } + + configureFieldInAllImplementations( + field = "lValueTypeRef", + implementationPredicate = { it.type in "FirVariableAssignmentImpl" }, + fieldPredicate = { it.defaultValueInImplementation == null } + ) { + default(it, "FirImplicitTypeRefImpl(null)") + useTypes(implicitTypeRefType) + } } } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 5734f64661b..46cd6765349 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -521,6 +521,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild variableAssignment.configure { +field("lValue", reference) + +field("lValueTypeRef", typeRef).withReplace() +field("rValue", expression).withTransform() } diff --git a/compiler/testData/diagnostics/tests/Properties.fir.kt b/compiler/testData/diagnostics/tests/Properties.fir.kt index 5bf038019ae..9f289318544 100644 --- a/compiler/testData/diagnostics/tests/Properties.fir.kt +++ b/compiler/testData/diagnostics/tests/Properties.fir.kt @@ -2,7 +2,7 @@ var x : Int = 1 + x get() : Int = 1 set(value : Long) { field = value.toInt() - field = 1.toLong() + field = 1.toLong() } val xx : Int = 1 + x @@ -19,4 +19,4 @@ class Test() { set(x) {a = x; field = x} public val i = 1 -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt index 2a39733a4c9..a32ba52480c 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/dataFlowInfo.fir.kt @@ -16,17 +16,17 @@ public class J { fun test() { val n = J.staticN foo(n) - J.staticNN = n + J.staticNN = n if (n != null) { foo(n) J.staticNN = n } val x: J? = null - J.staticNN = x + J.staticNN = x if (x != null) { J.staticNN = x } } -fun foo(j: J) {} \ No newline at end of file +fun foo(j: J) {} diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt index a7da5a027ea..e0b27d2fd0a 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/passToJava.fir.kt @@ -34,8 +34,8 @@ fun test(n: J?, nn: J) { // platform type with no annotation val platformJ = J.staticJ - J.staticNN = n - J.staticNN = platformN + J.staticNN = n + J.staticNN = platformN J.staticNN = nn J.staticNN = platformNN J.staticNN = platformJ @@ -58,8 +58,8 @@ fun test(n: J?, nn: J) { J.staticSet(platformN, platformN, platformN) J.staticSet(platformJ, platformJ, platformJ) - J().nn = n - J().nn = platformN + J().nn = n + J().nn = platformN J().nn = nn J().nn = platformNN J().nn = platformJ @@ -87,4 +87,4 @@ fun test(n: J?, nn: J) { J(n, n, n) J(platformN, platformN, platformN) J(platformJ, platformJ, platformJ) -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt index f29a54568c7..e3fa9a435b9 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/arrays.fir.kt @@ -28,7 +28,7 @@ fun main() { val raw = Test.rawAField raw.charSequences = arrayOf() - raw.charSequences = arrayOf() + raw.charSequences = arrayOf() raw.maps = arrayOf>() raw.maps = arrayOf>() diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt index b9ee17efd61..b8b40956f25 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/nonTrivialErasure.fir.kt @@ -25,5 +25,5 @@ fun main() { Test.rawAField.second = rawA.first.second rawA.listOfDoubles = strList - rawA.listOfDoubles = "" // first should be List + rawA.listOfDoubles = "" // first should be List } diff --git a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt index 280a3680e48..7ba47dca1e8 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt @@ -3,7 +3,7 @@ class A() { var x: Int = 0 get() = "s" set(value: String) { - field = value + field = value } val y: Int get(): String = "s" diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt index b5b7b27a885..d7774ccdef1 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt @@ -38,7 +38,7 @@ class Case8 { var x: Any = 0 get() = 0 set(value) { - field = null + field = null } } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index 56d7938c201..63d25e3c77d 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -908,12 +908,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } - add(FirErrors.MANY_LAMBDA_EXPRESSION_ARGUMENTS) { firDiagnostic -> - ManyLambdaExpressionArgumentsImpl( - firDiagnostic as FirPsiDiagnostic<*>, - token, - ) - } add(FirErrors.ASSIGNMENT_TYPE_MISMATCH) { firDiagnostic -> AssignmentTypeMismatchImpl( firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a), @@ -930,6 +924,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.MANY_LAMBDA_EXPRESSION_ARGUMENTS) { firDiagnostic -> + ManyLambdaExpressionArgumentsImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY) { firDiagnostic -> OverloadResolutionAmbiguityImpl( firDiagnostic.a.map { abstractFirBasedSymbol -> diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt index 409b54f4d0a..04f2441673d 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DifferentMavenStdlibVersionInspection.kt @@ -72,7 +72,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection, versions: List): List { + private fun createFixes(project: MavenProject, versionElement: GenericDomValue, versions: List): List { val bestVersion = versions.maxByOrNull(::MavenVersionComparable)!! if (bestVersion == versionElement.stringValue) { return emptyList() @@ -84,7 +84,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection, val newVersion: String, val versionResolved: String?) : + private class SetVersionQuickFix(val versionElement: GenericDomValue, val newVersion: String, val versionResolved: String?) : LocalQuickFix { override fun getName() = when (versionResolved) { null -> KotlinMavenBundle.message("fix.set.version.name", newVersion) diff --git a/idea/testData/checker/IncDec.fir.kt b/idea/testData/checker/IncDec.fir.kt index 139d73e25c2..b93c294f9ca 100644 --- a/idea/testData/checker/IncDec.fir.kt +++ b/idea/testData/checker/IncDec.fir.kt @@ -22,10 +22,10 @@ class WrongIncDec() { fun testWrongIncDec() { var x = WrongIncDec() - x++ - ++x - x-- - --x + x++ + ++x + x-- + --x } class UnitIncDec() { @@ -35,12 +35,12 @@ class UnitIncDec() { fun testUnitIncDec() { var x = UnitIncDec() - x++ - ++x - x-- - --x - x = x++ - x = x-- - x = ++x - x = --x + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x } diff --git a/idea/testData/checker/Properties.fir.kt b/idea/testData/checker/Properties.fir.kt index 56328fe5c10..395e526d70a 100644 --- a/idea/testData/checker/Properties.fir.kt +++ b/idea/testData/checker/Properties.fir.kt @@ -2,7 +2,7 @@ get() : Int = 1 set(value : Long) { field = value.toInt() - field = 1.toLong() + field = 1.toLong() } val xx : Int = 1 + x diff --git a/idea/testData/checker/regression/kt251.fir.kt b/idea/testData/checker/regression/kt251.fir.kt index ad84483a1d1..5de6ebe3836 100644 --- a/idea/testData/checker/regression/kt251.fir.kt +++ b/idea/testData/checker/regression/kt251.fir.kt @@ -2,7 +2,7 @@ class A() { var x: Int = 0 get() = "s" set(value: String) { - field = value + field = value } val y: Int get(): String = "s" diff --git a/jps-plugin/testData/incremental/classHierarchyAffected/varianceChanged/fir-build.log b/jps-plugin/testData/incremental/classHierarchyAffected/varianceChanged/fir-build.log deleted file mode 100644 index 61b0c9a92b5..00000000000 --- a/jps-plugin/testData/incremental/classHierarchyAffected/varianceChanged/fir-build.log +++ /dev/null @@ -1,18 +0,0 @@ -================ Step #1 ================= - -Compiling files: - src/A.kt - src/D.kt - src/useA.kt - src/useD.kt -End of files -Exit code: OK - -================ Step #2 ================= - -Compiling files: - src/useA.kt - src/useD.kt -End of files -Exit code: OK -