diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/superIsNotAnExpression.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/superIsNotAnExpression.kt index 3d2ec315190..d47496e516f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/superIsNotAnExpression.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/superIsNotAnExpression.kt @@ -7,7 +7,7 @@ class B: A() { invoke() super { - println('weird') + println('weird') } } } diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/operators/plusAndPlusAssign.kt b/compiler/fir/analysis-tests/testData/resolve/expresssions/operators/plusAndPlusAssign.kt index 37eb44f4e01..c89e1843cd2 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/operators/plusAndPlusAssign.kt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/operators/plusAndPlusAssign.kt @@ -5,5 +5,5 @@ class Foo { fun test() { var f = Foo() - f += f + f += f } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DeclarationCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DeclarationCheckers.kt index a778cd983e6..8d3712fbc85 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DeclarationCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DeclarationCheckers.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration +import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration @@ -15,4 +16,7 @@ object DeclarationCheckers { val MEMBER_DECLARATIONS: List> = DECLARATIONS + listOf( FirInfixFunctionDeclarationChecker ) + val CONSTRUCTORS: List> = MEMBER_DECLARATIONS + listOf( + FirConstructorChecker + ) } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorChecker.kt new file mode 100644 index 00000000000..016ea703713 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorChecker.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.analysis.checkers.declaration + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0 +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.declarations.* + +object FirConstructorChecker : FirDeclarationChecker() { + override fun check(declaration: FirConstructor, context: CheckerContext, reporter: DiagnosticReporter) { + val containingClass = context.containingDeclarations.lastOrNull() as? FirClass<*> ?: return + val source = declaration.source + val elementType = source?.elementType + if (elementType != KtNodeTypes.PRIMARY_CONSTRUCTOR && elementType != KtNodeTypes.SECONDARY_CONSTRUCTOR) { + return + } + when (containingClass.classKind) { + ClassKind.OBJECT -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT) + ClassKind.INTERFACE -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_INTERFACE) + ClassKind.ENUM_ENTRY -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT) + ClassKind.ENUM_CLASS -> if (declaration.visibility != Visibilities.PRIVATE) { + reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM) + } + ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED && + declaration.visibility != Visibilities.PRIVATE + ) { + reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED) + } + ClassKind.ANNOTATION_CLASS -> { + // DO NOTHING + } + } + } + + private inline fun DiagnosticReporter.report( + source: T?, + factory: FirDiagnosticFactory0 + ) { + source?.let { report(factory.on(it)) } + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt index 6a0c01e0fb3..299c96d21ee 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt @@ -12,6 +12,10 @@ import org.jetbrains.kotlin.fir.analysis.collectors.components.* import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.expressions.FirBreakExpression +import org.jetbrains.kotlin.fir.expressions.FirContinueExpression +import org.jetbrains.kotlin.fir.expressions.FirErrorLoop +import org.jetbrains.kotlin.fir.expressions.FirLoopJump import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.SessionHolder import org.jetbrains.kotlin.fir.resolve.collectImplicitReceivers @@ -66,11 +70,38 @@ abstract class AbstractDiagnosticCollector( element.acceptChildren(this) } - override fun visitRegularClass(regularClass: FirRegularClass) { + private fun visitJump(loopJump: FirLoopJump) { + loopJump.runComponents() + loopJump.acceptChildren(this) + loopJump.target.labeledElement.takeIf { it is FirErrorLoop }?.accept(this) + } + + override fun visitBreakExpression(breakExpression: FirBreakExpression) { + visitJump(breakExpression) + } + + override fun visitContinueExpression(continueExpression: FirContinueExpression) { + visitJump(continueExpression) + } + + private fun visitClassAndChildren(klass: FirClass<*>, type: ConeKotlinType) { val typeRef = buildResolvedTypeRef { - type = regularClass.defaultType() + this.type = type } - visitWithDeclarationAndReceiver(regularClass, regularClass.name, typeRef) + visitWithDeclarationAndReceiver(klass, (klass as? FirRegularClass)?.name, typeRef) + + } + + override fun visitRegularClass(regularClass: FirRegularClass) { + visitClassAndChildren(regularClass, regularClass.defaultType()) + } + + override fun visitSealedClass(sealedClass: FirSealedClass) { + visitClassAndChildren(sealedClass, sealedClass.defaultType()) + } + + override fun visitAnonymousObject(anonymousObject: FirAnonymousObject) { + visitClassAndChildren(anonymousObject, anonymousObject.defaultType()) } override fun visitSimpleFunction(simpleFunction: FirSimpleFunction) { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt index bbdc0bedcb1..8069014a826 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt @@ -34,7 +34,7 @@ class DeclarationCheckersDiagnosticComponent(collector: AbstractDiagnosticCollec } override fun visitConstructor(constructor: FirConstructor, data: CheckerContext) { - runCheck { DeclarationCheckers.MEMBER_DECLARATIONS.check(constructor, data, it) } + runCheck { DeclarationCheckers.CONSTRUCTORS.check(constructor, data, it) } } override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: CheckerContext) { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index db1dfac7911..d34fefec677 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -12,10 +12,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0 import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.FirErrorFunction -import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.diagnostics.* +import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind.* import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.FirErrorLoop import org.jetbrains.kotlin.fir.references.FirErrorNamedReference @@ -68,21 +66,24 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect private fun ConeSimpleDiagnostic.getFactory(): FirDiagnosticFactory0 { @Suppress("UNCHECKED_CAST") return when (kind) { - DiagnosticKind.Syntax -> FirErrors.SYNTAX_ERROR - DiagnosticKind.ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED - DiagnosticKind.UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL - DiagnosticKind.IllegalConstExpression -> FirErrors.ILLEGAL_CONST_EXPRESSION - DiagnosticKind.ConstructorInObject -> FirErrors.CONSTRUCTOR_IN_OBJECT - DiagnosticKind.DeserializationError -> FirErrors.DESERIALIZATION_ERROR - DiagnosticKind.InferenceError -> FirErrors.INFERENCE_ERROR - DiagnosticKind.NoSupertype -> FirErrors.NO_SUPERTYPE - DiagnosticKind.TypeParameterAsSupertype -> FirErrors.TYPE_PARAMETER_AS_SUPERTYPE - DiagnosticKind.EnumAsSupertype -> FirErrors.ENUM_AS_SUPERTYPE - DiagnosticKind.RecursionInSupertypes -> FirErrors.RECURSION_IN_SUPERTYPES - DiagnosticKind.RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES - DiagnosticKind.SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION - DiagnosticKind.Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION - DiagnosticKind.Other -> FirErrors.OTHER_ERROR + Syntax -> FirErrors.SYNTAX_ERROR + ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED + UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL + IllegalConstExpression -> FirErrors.ILLEGAL_CONST_EXPRESSION + DeserializationError -> FirErrors.DESERIALIZATION_ERROR + InferenceError -> FirErrors.INFERENCE_ERROR + NoSupertype -> FirErrors.NO_SUPERTYPE + TypeParameterAsSupertype -> FirErrors.TYPE_PARAMETER_AS_SUPERTYPE + EnumAsSupertype -> FirErrors.ENUM_AS_SUPERTYPE + RecursionInSupertypes -> FirErrors.RECURSION_IN_SUPERTYPES + RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES + SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION + Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION + ExpressionRequired -> FirErrors.EXPRESSION_REQUIRED + JumpOutsideLoop -> FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP + NotLoopLabel -> FirErrors.NOT_A_LOOP_LABEL + VariableExpected -> FirErrors.VARIABLE_EXPECTED + Other -> FirErrors.OTHER_ERROR else -> throw IllegalArgumentException("Unsupported diagnostic kind: $kind at $javaClass") } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 97766c1f92f..8a759f40cf6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -29,6 +29,9 @@ object FirErrors { val RECURSION_IN_SUPERTYPES by error0() val RECURSION_IN_IMPLICIT_TYPES by error0() val ERROR_FROM_JAVA_RESOLUTION by error0() + val EXPRESSION_REQUIRED by error0() + val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error0() + val NOT_A_LOOP_LABEL by error0() val OTHER_ERROR by error0() val TYPE_MISMATCH by error2() val VARIABLE_EXPECTED by error0() @@ -37,9 +40,12 @@ object FirErrors { val INAPPLICABLE_INFIX_MODIFIER by existing(Errors.INAPPLICABLE_INFIX_MODIFIER) val CONSTRUCTOR_IN_OBJECT by existing(Errors.CONSTRUCTOR_IN_OBJECT) + val CONSTRUCTOR_IN_INTERFACE by existing(Errors.CONSTRUCTOR_IN_INTERFACE) + val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by existing(Errors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM) + val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by existing(Errors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED) - val REPEATED_MODIFIER by error1() - val REDUNDANT_MODIFIER by error2() - val DEPRECATED_MODIFIER_PAIR by error2() - val INCOMPATIBLE_MODIFIERS by error2() + val REPEATED_MODIFIER by error1() + val REDUNDANT_MODIFIER by error2() + val DEPRECATED_MODIFIER_PAIR by error2() + val INCOMPATIBLE_MODIFIERS by error2() } diff --git a/compiler/fir/raw-fir/fir-common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/fir-common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index a09441333b3..b5c73af7d9d 100644 --- a/compiler/fir/raw-fir/fir-common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/fir-common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.builder -import com.intellij.psi.PsiElement import com.intellij.psi.tree.IElementType import org.jetbrains.kotlin.KtNodeTypes.* import org.jetbrains.kotlin.descriptors.Modality @@ -36,7 +35,6 @@ import org.jetbrains.kotlin.lexer.KtTokens.OPEN_QUOTE import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtClassOrObject -import org.jetbrains.kotlin.psi.KtStringTemplateExpression import org.jetbrains.kotlin.psi.KtUnaryExpression import org.jetbrains.kotlin.resolve.constants.evaluate.* import org.jetbrains.kotlin.util.OperatorNameConventions @@ -57,6 +55,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte abstract fun T.getReferencedNameAsName(): Name abstract fun T.getLabelName(): String? abstract fun T.getExpressionInParentheses(): T? + abstract fun T.getAnnotatedExpression(): T? abstract fun T.getChildNodeByType(type: IElementType): T? abstract val T?.selectorExpression: T? @@ -173,12 +172,13 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte fun FirLoopJumpBuilder.bindLabel(expression: T): FirLoopJumpBuilder { val labelName = expression.getLabelName() val lastLoopTarget = context.firLoopTargets.lastOrNull() + val sourceElement = expression.toFirSourceElement() if (labelName == null) { target = lastLoopTarget ?: FirLoopTarget(labelName).apply { bind( buildErrorLoop( - expression.getSourceOrNull(), - ConeSimpleDiagnostic("Cannot bind unlabeled jump to a loop", DiagnosticKind.Syntax) + sourceElement, + ConeSimpleDiagnostic("Cannot bind unlabeled jump to a loop", DiagnosticKind.JumpOutsideLoop) ) ) } @@ -192,7 +192,11 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte target = FirLoopTarget(labelName).apply { bind( buildErrorLoop( - expression.getSourceOrNull(), ConeSimpleDiagnostic("Cannot bind label $labelName to a loop", DiagnosticKind.Syntax) + sourceElement, + ConeSimpleDiagnostic( + "Cannot bind label $labelName to a loop", + lastLoopTarget?.let { DiagnosticKind.NotLoopLabel } ?: DiagnosticKind.JumpOutsideLoop + ) ) ) } @@ -200,14 +204,10 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte return this } - /**** Conversion utils ****/ - private fun T.getSourceOrNull(): FirSourceElement? { - return if (this is PsiElement) FirPsiSourceElement(this) else null - } - fun generateConstantExpressionByLiteral(expression: T): FirExpression { val type = expression.elementType val text: String = expression.asText + val sourceElement = expression.toFirSourceElement() val convertedText: Any? = when (type) { INTEGER_CONSTANT, FLOAT_CONSTANT -> parseNumericLiteral(text, type) BOOLEAN_CONSTANT -> parseBoolean(text) @@ -217,7 +217,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte INTEGER_CONSTANT -> { val kind = when { convertedText !is Long -> return buildErrorExpression { - source = expression.getSourceOrNull() + source = sourceElement diagnostic = ConeSimpleDiagnostic( "Incorrect constant expression: $text", DiagnosticKind.IllegalConstExpression @@ -240,44 +240,44 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } buildConstOrErrorExpression( - expression.getSourceOrNull(), + sourceElement, kind, convertedText, - ConeSimpleDiagnostic("Incorrect integer literal: $text", DiagnosticKind.Syntax) + ConeSimpleDiagnostic("Incorrect integer literal: $text", DiagnosticKind.IllegalConstExpression) ) } FLOAT_CONSTANT -> if (convertedText is Float) { buildConstOrErrorExpression( - expression.getSourceOrNull(), + sourceElement, FirConstKind.Float, convertedText, - ConeSimpleDiagnostic("Incorrect float: $text", DiagnosticKind.Syntax) + ConeSimpleDiagnostic("Incorrect float: $text", DiagnosticKind.IllegalConstExpression) ) } else { buildConstOrErrorExpression( - expression.getSourceOrNull(), + sourceElement, FirConstKind.Double, convertedText as Double, - ConeSimpleDiagnostic("Incorrect double: $text", DiagnosticKind.Syntax) + ConeSimpleDiagnostic("Incorrect double: $text", DiagnosticKind.IllegalConstExpression) ) } CHARACTER_CONSTANT -> buildConstOrErrorExpression( - expression.getSourceOrNull(), + sourceElement, FirConstKind.Char, text.parseCharacter(), - ConeSimpleDiagnostic("Incorrect character: $text", DiagnosticKind.Syntax) + ConeSimpleDiagnostic("Incorrect character: $text", DiagnosticKind.IllegalConstExpression) ) BOOLEAN_CONSTANT -> buildConstExpression( - expression.getSourceOrNull(), + sourceElement, FirConstKind.Boolean, convertedText as Boolean ) NULL -> buildConstExpression( - expression.getSourceOrNull(), + sourceElement, FirConstKind.Null, null ) @@ -287,7 +287,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } fun Array.toInterpolatingCall( - base: KtStringTemplateExpression?, + base: T, convertTemplateEntry: T?.(String) -> FirExpression ): FirExpression { return buildStringConcatenationCall { @@ -300,11 +300,11 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte OPEN_QUOTE, CLOSING_QUOTE -> continue@L LITERAL_STRING_TEMPLATE_ENTRY -> { sb.append(entry.asText) - buildConstExpression(entry.getSourceOrNull(), FirConstKind.String, entry.asText) + buildConstExpression(entry.toFirSourceElement(), FirConstKind.String, entry.asText) } ESCAPE_STRING_TEMPLATE_ENTRY -> { sb.append(entry.unescapedValue) - buildConstExpression(entry.getSourceOrNull(), FirConstKind.String, entry.unescapedValue) + buildConstExpression(entry.toFirSourceElement(), FirConstKind.String, entry.unescapedValue) } SHORT_STRING_TEMPLATE_ENTRY, LONG_STRING_TEMPLATE_ENTRY -> { hasExpressions = true @@ -322,7 +322,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte else -> { hasExpressions = true buildErrorExpression { - source = entry.getSourceOrNull() + source = entry.toFirSourceElement() diagnostic = ConeSimpleDiagnostic("Incorrect template entry: ${entry.asText}", DiagnosticKind.Syntax) } } @@ -361,7 +361,8 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte // TODO: Refactor, support receiver capturing in case of a.b fun generateIncrementOrDecrementBlock( - baseExpression: KtUnaryExpression?, + baseExpression: T, + operationReference: T?, argument: T?, callName: Name, prefix: Boolean, @@ -383,7 +384,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte val resultInitializer = buildFunctionCall { source = baseSource calleeReference = buildSimpleNamedReference { - source = baseExpression?.operationReference?.toFirSourceElement() + source = operationReference?.toFirSourceElement() name = callName } explicitReceiver = generateResolvedAccessExpression(source, temporaryVariable) @@ -432,13 +433,13 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte when (tokenType) { REFERENCE_EXPRESSION -> { return buildSimpleNamedReference { - source = left.getSourceOrNull() + source = left.toFirSourceElement() name = left.getReferencedNameAsName() } } THIS_EXPRESSION -> { return buildExplicitThisReference { - source = left.getSourceOrNull() + source = left.toFirSourceElement() labelName = left.getLabelName() } } @@ -450,7 +451,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte firMemberAccess.calleeReference } else { buildErrorNamedReference { - source = left.getSourceOrNull() + source = left.toFirSourceElement() diagnostic = ConeSimpleDiagnostic("Unsupported qualified LValue: ${left.asText}", DiagnosticKind.Syntax) } } @@ -458,11 +459,14 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte PARENTHESIZED -> { return initializeLValue(left.getExpressionInParentheses(), convertQualified) } + ANNOTATED_EXPRESSION -> { + return initializeLValue(left.getAnnotatedExpression(), convertQualified) + } } } return buildErrorNamedReference { - source = left.getSourceOrNull() - diagnostic = ConeSimpleDiagnostic("Unsupported LValue: $tokenType", DiagnosticKind.Syntax) + source = left?.toFirSourceElement() + diagnostic = ConeSimpleDiagnostic("Unsupported LValue: $tokenType", DiagnosticKind.VariableExpected) } } @@ -497,7 +501,9 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte argumentList = buildBinaryArgumentList( this@generateAssignment?.convert() ?: buildErrorExpression { source = null - diagnostic = ConeSimpleDiagnostic("Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.Syntax) + diagnostic = ConeSimpleDiagnostic( + "Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionRequired + ) }, value ) @@ -678,7 +684,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte fun List>.generateCopyFunction( session: FirSession, - classOrObject: KtClassOrObject?, + classOrObject: T, classBuilder: AbstractFirRegularClassBuilder, packageFqName: FqName, classFqName: FqName, diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt index a9e2777dcc1..00aea2fc1a0 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/BaseConverter.kt @@ -71,6 +71,14 @@ open class BaseConverter( return null } + override fun LighterASTNode.getAnnotatedExpression(): LighterASTNode? { + this.forEachChildren { + if (it.isExpression()) return it + } + + return null + } + override fun LighterASTNode.getChildNodeByType(type: IElementType): LighterASTNode? { return this.getChildNodesByType(type).firstOrNull() } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index 09bdb07747f..5dd9a24122a 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -462,7 +462,7 @@ class DeclarationsConverter( baseSession, this, context.packageFqName, context.className, firPrimaryConstructor ) zippedParameters.generateCopyFunction( - baseSession, null, this, context.packageFqName, context.className, firPrimaryConstructor + baseSession, classNode, this, context.packageFqName, context.className, firPrimaryConstructor ) // TODO: equals, hashCode, toString } @@ -718,15 +718,7 @@ class DeclarationsConverter( } } - val delegatedSelfTypeRef = - if (classWrapper.isObjectLiteral()) buildErrorTypeRef { - source = secondaryConstructor.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic( - "Constructor in object", - DiagnosticKind.ConstructorInObject - ) - } - else classWrapper.delegatedSelfTypeRef + val delegatedSelfTypeRef = classWrapper.delegatedSelfTypeRef val explicitVisibility = modifiers.getVisibility() val status = FirDeclarationStatusImpl(explicitVisibility, Modality.FINAL).apply { @@ -777,15 +769,7 @@ class DeclarationsConverter( val isImplicit = constructorDelegationCall.asText.isEmpty() val isThis = (isImplicit && classWrapper.hasPrimaryConstructor) || thisKeywordPresent val delegatedType = - if (classWrapper.isObjectLiteral() || classWrapper.isInterface()) when { - isThis -> buildErrorTypeRef { - diagnostic = ConeSimpleDiagnostic("Constructor in object", DiagnosticKind.ConstructorInObject) - } - else -> buildErrorTypeRef { - diagnostic = ConeSimpleDiagnostic("No super type", DiagnosticKind.Syntax) - } - } - else when { + when { isThis -> classWrapper.delegatedSelfTypeRef else -> classWrapper.delegatedSuperTypeRef } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 13c7030b255..8f9f62d02fd 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -55,7 +55,11 @@ class ExpressionsConverter( ) : BaseConverter(session, tree, offset, context) { inline fun getAsFirExpression(expression: LighterASTNode?, errorReason: String = ""): R { - return expression?.let { convertExpression(it, errorReason) } as? R ?: (buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax)) as R) + return expression?.let { + convertExpression(it, errorReason) + } as? R ?: buildErrorExpression( + null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired) + ) as R } /***** EXPRESSIONS *****/ @@ -103,7 +107,7 @@ class ExpressionsConverter( OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression) FUN -> declarationsConverter.convertFunctionDeclaration(expression) - else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax)) + else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired)) } } @@ -310,9 +314,13 @@ class ExpressionsConverter( private fun convertUnaryExpression(unaryExpression: LighterASTNode): FirExpression { lateinit var operationTokenName: String var argument: LighterASTNode? = null + var operationReference: LighterASTNode? = null unaryExpression.forEachChildren { when (it.tokenType) { - OPERATION_REFERENCE -> operationTokenName = it.asText + OPERATION_REFERENCE -> { + operationReference = it + operationTokenName = it.asText + } else -> if (it.isExpression()) argument = it } } @@ -330,7 +338,8 @@ class ExpressionsConverter( conventionCallName != null -> { if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) { return generateIncrementOrDecrementBlock( - null, + unaryExpression, + operationReference, argument, callName = conventionCallName, prefix = unaryExpression.tokenType == PREFIX_EXPRESSION @@ -548,7 +557,7 @@ class ExpressionsConverter( * @see org.jetbrains.kotlin.parsing.KotlinExpressionParsing.parseStringTemplate */ private fun convertStringTemplate(stringTemplate: LighterASTNode): FirExpression { - return stringTemplate.getChildrenAsArray().toInterpolatingCall(null) { convertShortOrLongStringTemplate(it) } + return stringTemplate.getChildrenAsArray().toInterpolatingCall(stringTemplate) { convertShortOrLongStringTemplate(it) } } private fun LighterASTNode?.convertShortOrLongStringTemplate(errorReason: String): FirExpression { @@ -1053,8 +1062,9 @@ class ExpressionsConverter( } val jumpBuilder = if (isBreak) FirBreakExpressionBuilder() else FirContinueExpressionBuilder() + val sourceElement = jump.toFirSourceElement() return jumpBuilder.apply { - source = jump.toFirSourceElement() + source = sourceElement }.bindLabel(jump).build() } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 1f17c1b8d52..6faef7ede4c 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -82,6 +82,10 @@ class RawFirBuilder( return (this as KtParenthesizedExpression).expression } + override fun PsiElement.getAnnotatedExpression(): PsiElement? { + return (this as KtAnnotatedExpression).baseExpression + } + override val PsiElement?.selectorExpression: PsiElement? get() = (this as? KtQualifiedExpression)?.selectorExpression @@ -135,14 +139,14 @@ class RawFirBuilder( if (stubMode) buildExpressionStub() else with(this()) { convertSafe() ?: buildErrorExpression( - this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax), + this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired), ) } private fun KtExpression?.toFirExpression(errorReason: String): FirExpression = if (stubMode) buildExpressionStub() else convertSafe() ?: buildErrorExpression( - this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax), + this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired), ) private fun KtExpression.toFirStatement(errorReason: String): FirStatement = @@ -152,16 +156,13 @@ class RawFirBuilder( convert() private fun KtDeclaration.toFirDeclaration( - delegatedSuperType: FirTypeRef?, delegatedSelfType: FirResolvedTypeRef?, owner: KtClassOrObject, hasPrimaryConstructor: Boolean, + delegatedSuperType: FirTypeRef, delegatedSelfType: FirResolvedTypeRef, owner: KtClassOrObject, hasPrimaryConstructor: Boolean, ): FirDeclaration { return when (this) { is KtSecondaryConstructor -> { toFirConstructor( delegatedSuperType, - delegatedSelfType ?: buildErrorTypeRef { - source = this@toFirDeclaration.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic("Constructor in object", DiagnosticKind.ConstructorInObject) - }, + delegatedSelfType, owner, hasPrimaryConstructor, ) @@ -172,7 +173,7 @@ class RawFirBuilder( primaryConstructor?.valueParameters?.isEmpty() ?: owner.secondaryConstructors.let { constructors -> constructors.isEmpty() || constructors.any { it.valueParameters.isEmpty() } } - toFirEnumEntry(delegatedSelfType!!, ownerClassHasDefaultConstructor) + toFirEnumEntry(delegatedSelfType, ownerClassHasDefaultConstructor) } else -> convert() } @@ -397,7 +398,7 @@ class RawFirBuilder( delegatedSelfTypeRef: FirTypeRef?, delegatedEnumSuperTypeRef: FirTypeRef?, classKind: ClassKind, - ): FirTypeRef? { + ): FirTypeRef { var superTypeCallEntry: KtSuperTypeCallEntry? = null var delegatedSuperTypeRef: FirTypeRef? = null for (superTypeListEntry in superTypeListEntries) { @@ -452,7 +453,7 @@ class RawFirBuilder( if (container.superTypeRefs.isEmpty()) { container.superTypeRefs += defaultDelegatedSuperTypeRef } - if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef + if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef ?: implicitAnyType // TODO: in case we have no primary constructor, // it may be not possible to determine delegated super type right here @@ -687,13 +688,13 @@ class RawFirBuilder( symbol = FirAnonymousObjectSymbol() val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this) objectDeclaration.extractAnnotationsTo(this) - objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType, null, ClassKind.CLASS) + val delegatedSuperType = objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType, null, ClassKind.CLASS) typeRef = delegatedSelfType for (declaration in objectDeclaration.declarations) { declarations += declaration.toFirDeclaration( - delegatedSuperType = null, - delegatedSelfType = null, + delegatedSuperType, + delegatedSelfType, owner = objectDeclaration, hasPrimaryConstructor = false, ) @@ -866,7 +867,7 @@ class RawFirBuilder( } private fun KtSecondaryConstructor.toFirConstructor( - delegatedSuperTypeRef: FirTypeRef?, + delegatedSuperTypeRef: FirTypeRef, delegatedSelfTypeRef: FirTypeRef, owner: KtClassOrObject, hasPrimaryConstructor: Boolean, @@ -885,7 +886,11 @@ class RawFirBuilder( isFromEnumClass = owner.hasModifier(ENUM_KEYWORD) } symbol = FirConstructorSymbol(callableIdForClassConstructor()) - delegatedConstructor = getDelegationCall().convert(delegatedSuperTypeRef, delegatedSelfTypeRef, hasPrimaryConstructor) + delegatedConstructor = getDelegationCall().convert( + delegatedSuperTypeRef, + delegatedSelfTypeRef, + hasPrimaryConstructor + ) this@RawFirBuilder.context.firFunctionTargets += target extractAnnotationsTo(this) typeParameters += typeParametersFromSelfType(delegatedSelfTypeRef) @@ -898,7 +903,7 @@ class RawFirBuilder( } private fun KtConstructorDelegationCall.convert( - delegatedSuperTypeRef: FirTypeRef?, + delegatedSuperTypeRef: FirTypeRef, delegatedSelfTypeRef: FirTypeRef, hasPrimaryConstructor: Boolean, ): FirDelegatedConstructorCall { @@ -906,10 +911,7 @@ class RawFirBuilder( val source = this.toFirSourceElement() val delegatedType = when { isThis -> delegatedSelfTypeRef - else -> delegatedSuperTypeRef ?: buildErrorTypeRef { - this.source = source - diagnostic = ConeSimpleDiagnostic("No super type", DiagnosticKind.Syntax) - } + else -> delegatedSuperTypeRef } return buildDelegatedConstructorCall { this.source = source @@ -1449,7 +1451,7 @@ class RawFirBuilder( conventionCallName != null -> { if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) { return generateIncrementOrDecrementBlock( - expression, argument, + expression, expression.operationReference, argument, callName = conventionCallName, prefix = expression is KtPrefixExpression, ) { (this as KtExpression).toFirExpression("Incorrect expression inside inc/dec") } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorInObject.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorInObject.txt index 64e9e3b656c..0a8589e7a9b 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorInObject.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/constructorInObject.txt @@ -45,8 +45,8 @@ FILE: constructorInObject.kt } public? final? val anonObject: = object : R|kotlin/Any| { - public? constructor(): { - super<>() + public? constructor(): R|anonymous| { + super() } } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt index 50ac6615bf8..059e642f2bf 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder import org.jetbrains.kotlin.fir.builder.FirBuilderDsl import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorLoopBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorLoopBuilder.kt index d468e62cf1c..2bd7bd2e3a0 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorLoopBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorLoopBuilder.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder import org.jetbrains.kotlin.fir.builder.FirBuilderDsl import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirErrorLoop diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt index 6b3b93df513..410af49c8f1 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.expressions.impl import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirErrorExpression import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -22,7 +23,7 @@ internal class FirErrorExpressionImpl( override val source: FirSourceElement?, override val diagnostic: ConeDiagnostic, ) : FirErrorExpression() { - override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, diagnostic) + override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic)) override val annotations: List get() = emptyList() override fun acceptChildren(visitor: FirVisitor, data: D) { diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt index 31bce4d9205..eda38b5c877 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.expressions.impl import org.jetbrains.kotlin.fir.FirLabel import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirErrorLoop @@ -27,7 +28,7 @@ internal class FirErrorLoopImpl( override val diagnostic: ConeDiagnostic, ) : FirErrorLoop() { override var block: FirBlock = FirEmptyExpressionBlock() - override var condition: FirExpression = FirErrorExpressionImpl(source, diagnostic) + override var condition: FirExpression = FirErrorExpressionImpl(source, ConeStubDiagnostic(diagnostic)) override fun acceptChildren(visitor: FirVisitor, data: D) { annotations.forEach { it.accept(visitor, data) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index 74dcf02f424..10612cd88fb 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -9,10 +9,14 @@ class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind enum class DiagnosticKind { Syntax, + ExpressionRequired, + NotLoopLabel, + JumpOutsideLoop, + VariableExpected, + ReturnNotAllowed, UnresolvedLabel, IllegalConstExpression, - ConstructorInObject, DeserializationError, InferenceError, NoSupertype, 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 dc447d8fffa..5cec5333fe6 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 @@ -139,8 +139,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() impl(errorLoop) { default("block", "FirEmptyExpressionBlock()") - default("condition", "FirErrorExpressionImpl(source, diagnostic)") - useTypes(emptyExpressionBlock) + default("condition", "FirErrorExpressionImpl(source, ConeStubDiagnostic(diagnostic))") + useTypes(emptyExpressionBlock, coneStubDiagnosticType) } impl(expression, "FirExpressionStub") { @@ -390,8 +390,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() impl(errorExpression) { defaultEmptyList("annotations") - default("typeRef", "FirErrorTypeRefImpl(source, diagnostic)") - useTypes(errorTypeRefImpl) + default("typeRef", "FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic))") + useTypes(errorTypeRefImpl, coneStubDiagnosticType) } impl(resolvedFunctionTypeRef) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt index e3c16115f77..526a5ba533d 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt @@ -65,6 +65,7 @@ val pureAbstractElementType = generatedType("FirPureAbstractElement") val effectDeclarationType = type("fir.contracts.description", "ConeEffectDeclaration") val emptyContractDescriptionType = generatedType("contracts.impl", "FirEmptyContractDescription") val coneDiagnosticType = generatedType("diagnostics", "ConeDiagnostic") +val coneStubDiagnosticType = generatedType("diagnostics", "ConeStubDiagnostic") val dslBuilderAnnotationType = generatedType("builder", "FirBuilderDsl") val firImplementationDetailType = generatedType("FirImplementationDetail") \ No newline at end of file diff --git a/compiler/testData/codegen/box/operatorConventions/annotatedAssignment.kt b/compiler/testData/codegen/box/operatorConventions/annotatedAssignment.kt index 0f277851f7a..2a2bc1b115b 100644 --- a/compiler/testData/codegen/box/operatorConventions/annotatedAssignment.kt +++ b/compiler/testData/codegen/box/operatorConventions/annotatedAssignment.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR @Target(AnnotationTarget.EXPRESSION) @Retention(AnnotationRetention.SOURCE) annotation class Annotation diff --git a/compiler/testData/diagnostics/tests/BreakContinue.fir.kt b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt index 3f7bfc61058..456a6b1b623 100644 --- a/compiler/testData/diagnostics/tests/BreakContinue.fir.kt +++ b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt @@ -3,26 +3,26 @@ class C { fun f (a : Boolean, b : Boolean) { b@ while (true) a@ { - break@f + break@f break break@b - break@a + break@a } - continue + continue b@ while (true) a@ { - continue@f + continue@f continue continue@b - continue@a + continue@a } - break + break - continue@f - break@f + continue@f + break@f } fun containsBreak(a: String?, b: String?) { @@ -50,7 +50,7 @@ class C { fun containsIllegalBreak(a: String?) { loop@ while(a == null) { - break@label + break@label } a.compareTo("2") } @@ -78,7 +78,7 @@ class C { l@ for (el in array) { break } - if (true) break else break@l + if (true) break else break@l } a.compareTo("2") } @@ -86,7 +86,7 @@ class C { fun twoLabelsOnLoop() { label1@ label2@ for (i in 1..100) { if (i > 0) { - break@label1 + break@label1 } else { break@label2 diff --git a/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt b/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt deleted file mode 100644 index 0d72e61d39f..00000000000 --- a/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.fir.kt +++ /dev/null @@ -1,92 +0,0 @@ -// !LANGUAGE: +AllowBreakAndContinueInsideWhen - -fun breakContinueInWhen(i: Int) { - for (y in 0..10) { - when(i) { - 0 -> continue - 1 -> break - 2 -> { - for(z in 0..10) { - break - } - for(w in 0..10) { - continue - } - } - } - } -} - - -fun breakContinueInWhenWithWhile(i: Int, j: Int) { - while (i > 0) { - when (i) { - 0 -> continue - 1 -> break - 2 -> { - while (j > 0) { - break - } - } - } - } -} - -fun breakContinueInWhenWithDoWhile(i: Int, j: Int) { - do { - when (i) { - 0 -> continue - 1 -> break - 2 -> { - do { - if (j == 5) break - if (j == 10) continue - } while (j > 0) - } - } - } while (i > 0) -} - -fun labeledBreakContinue(i: Int) { - outer@ for (y in 0..10) { - when (i) { - 0 -> continue@outer - 1 -> break@outer - } - } -} - -fun testBreakContinueInWhenInWhileCondition() { - var i = 0 - while ( - when (i) { - 1 -> break - 2 -> continue - else -> true - } - ) { - ++i - } -} - -fun testBreakContinueInWhenInDoWhileCondition() { - var i = 0 - do { - ++i - } while ( - when (i) { - 1 -> break - 2 -> continue - else -> true - } - ) -} - -fun testBreakContinueInWhenInForIteratorExpression(xs: List, i: Int) { - for (x in when (i) { - 1 -> break - 2 -> continue - else -> xs - }) { - } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.kt b/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.kt index dc258660add..25181088c0d 100644 --- a/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.kt +++ b/compiler/testData/diagnostics/tests/BreakContinueInWhen_after.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +AllowBreakAndContinueInsideWhen fun breakContinueInWhen(i: Int) { diff --git a/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt b/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt index 719495e6aec..e75762bdb11 100644 --- a/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt +++ b/compiler/testData/diagnostics/tests/CharacterLiterals.fir.kt @@ -1,13 +1,13 @@ fun test(c : Char) { - test('') + test('') test('a') - test('aa') - test('a) - test(' - test(0' + test('aa') + test('a) + test(' + test(0' test('\n') test('\\') - test('''') + test('''') test('\'') test('\"') } diff --git a/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt index c20e2ea7b61..33abadba3ea 100644 --- a/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt +++ b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.fir.kt @@ -2,11 +2,11 @@ // KT-451 Incorrect character literals cause assertion failures fun ff() { - val b = '' - val c = '23' - val d = 'a - val e = 'ab - val f = '\' + val b = '' + val c = '23' + val d = 'a + val e = 'ab + val f = '\' } fun test() { @@ -19,19 +19,19 @@ fun test() { '\'' '\\' '\$' - '\x' - '\123' - '\ra' - '\000' - '\000' + '\x' + '\123' + '\ra' + '\000' + '\000' '\u0000' '\u000a' '\u000A' - '\u' - '\u0' - '\u00' - '\u000' - '\u000z' - '\\u000' - '\' + '\u' + '\u0' + '\u00' + '\u000' + '\u000z' + '\\u000' + '\' } diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt index 89c5d1c5d1c..b1fcd991b3a 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt @@ -14,7 +14,7 @@ class C() : B() { this.c = 34 super.c = 3535 //repeat for 'c' - getInt() = 12 + getInt() = 12 } fun foo1(c: C) { @@ -42,27 +42,27 @@ fun cannotBe() { var i: Int = 5 z = 30; - "" = ""; - foo() = Unit; + "" = ""; + foo() = Unit; - (i as Int) = 34 - (i is Int) = false - A() = A() - 5 = 34 + (i as Int) = 34 + (i is Int) = false + A() = A() + 5 = 34 } fun canBe(i0: Int, j: Int) { var i = i0 - (label@ i) = 34 + (label@ i) = 34 - (label@ j) = 34 //repeat for j + (label@ j) = 34 //repeat for j val a = A() - (l@ a.a) = 3894 + (l@ a.a) = 3894 } fun canBe2(j: Int) { - (label@ j) = 34 + (label@ j) = 34 } class A() { @@ -77,11 +77,11 @@ class Test() { getInt() += 343 (f@ getInt()) += 343 - 1++ - (r@ 1)++ + 1++ + (r@ 1)++ - getInt()++ - (m@ getInt())++ + getInt()++ + (m@ getInt())++ this++ @@ -106,7 +106,7 @@ class Test() { b += 34 a++ - (l@ a)++ + (l@ a)++ (a)++ } diff --git a/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt index 7ee1f433ccc..8eb172ee81e 100644 --- a/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/ObjectWithConstructor.fir.kt @@ -1,24 +1,24 @@ -object A1() { - constructor(x: Int = "", y: Int) : this() { +object A1() { + constructor(x: Int = "", y: Int) : this() { x + y } } -object A2 public constructor(private val prop: Int) { - constructor(x: Int = "", y: Int) : this(x * y) { +object A2 public constructor(private val prop: Int) { + constructor(x: Int = "", y: Int) : this(x * y) { x + y } } -val x = object (val prop: Int) { - constructor() : this(1) { +val x = object (val prop: Int) { + constructor() : this(1) { val x = 1 x * x } } class A3 { - companion object B(val prop: Int) { - public constructor() : this(2) + companion object B(val prop: Int) { + public constructor() : this(2) } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt index ba80db27c84..8fec6b20155 100644 --- a/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt +++ b/compiler/testData/diagnostics/tests/StringPrefixAndSuffix.fir.kt @@ -11,7 +11,7 @@ fun test(a: Any) { a foo"asd${a}sfsa" a foo"""sdf""" a foo'd' - a foo'' + a foo'' a foo""foo a a foo"asd"foo a @@ -19,17 +19,17 @@ fun test(a: Any) { a foo"asd${a}sfsa"foo a a foo"""sdf"""foo a a foo'd'foo a - a foo''foo a + a foo''foo a a in"foo" a in"""foo""" a in's' - a in'' + a in'' a !in"foo" a !in"""foo""" a !in's' - a !in'' + a !in'' if("s"is Any) {} if("s"is Any) {} diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt b/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt index f4bc01edac2..6d9d6109a25 100644 --- a/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/TraitWithConstructor.fir.kt @@ -9,7 +9,7 @@ interface T2 constructor() {} interface T3 private constructor(a: Int) {} interface T4 { - constructor(a: Int) { + constructor(a: Int) { val b: Int = 1 } } diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt index ee288a47ee3..f9320366c44 100644 --- a/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.fir.kt @@ -18,4 +18,4 @@ class G { companion object F } -object H() +object H() diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt index bee871f04f1..430fa697b4d 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.fir.kt @@ -9,7 +9,7 @@ annotation class Foo( annotation class Bar( val a: Array = [' '], - val b: Array = ["", ''], + val b: Array = ["", ''], val c: Array = [1] ) diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt index da8fe3d06ff..6e917ebefaa 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.fir.kt @@ -1,17 +1,17 @@ fun test() { - l@ for (i in if (true) 1..10 else continue@l) {} - for (i in if (true) 1..10 else continue) {} + l@ for (i in if (true) 1..10 else continue@l) {} + for (i in if (true) 1..10 else continue) {} - while (break) {} - l@ while (break@l) {} + while (break) {} + l@ while (break@l) {} - do {} while (continue) - l@ do {} while (continue@l) + do {} while (continue) + l@ do {} while (continue@l) //KT-5704 var i = 0 - while (if(i++ == 10) break else continue) {} + while (if(i++ == 10) break else continue) {} } fun test2(b: Boolean) { diff --git a/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt index 5bc951d9c65..d04af15180f 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt @@ -1,5 +1,5 @@ -fun foo1() = while (b()) {} +fun foo1() = while (b()) {} fun foo2() = for (i in 10) {} diff --git a/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt index 626811aacc7..b2d5f04a659 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt @@ -19,7 +19,7 @@ class Test3 { } fun test4() { - break@test4 + break@test4 } class Test5 { @@ -43,11 +43,11 @@ class Test6 { class Test7 { fun Test7() { Test8@ while (true) { - break@Test7 + break@Test7 } Test7@ while (true) { - break@Test8 + break@Test8 } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt index a13c423c946..4ea964a1554 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt @@ -15,7 +15,7 @@ fun main() { } //KT-351 Distinguish statement and expression positions -val w = while (true) {} +val w = while (true) {} fun foo() { var z = 2 @@ -152,12 +152,12 @@ fun bar(a: Unit) {} fun testStatementInExpressionContext() { var z = 34 - val a1: Unit = z = 334 + val a1: Unit = z = 334 val f = for (i in 1..10) {} - if (true) return z = 34 - return while (true) {} + if (true) return z = 34 + return while (true) {} } fun testStatementInExpressionContext2() { - val a2: Unit = while(true) {} + val a2: Unit = while(true) {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt index 6fb3b31efdc..f645b143f27 100644 --- a/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt +++ b/compiler/testData/diagnostics/tests/dataClasses/dataObject.fir.kt @@ -1 +1 @@ -data object Object(val x: Int, val y: Int) +data object Object(val x: Int, val y: Int) diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt index e42796507fe..99b1a0e45f7 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt @@ -4,7 +4,7 @@ fun foo(block: () -> (() -> Int)) {} fun test() { - val x = fun named1(x: Int): Int { return 1 } + val x = fun named1(x: Int): Int { return 1 } x checkType { _>() } foo { fun named2(): Int {return 1} } @@ -45,12 +45,12 @@ fun test() { x4 checkType { _>() } { y: Int -> fun named14(): Int {return 1} } - val b = (fun named15(): Boolean { return true })() + val b = (fun named15(): Boolean { return true })() - baz(fun named16(){}) + baz(fun named16(){}) } -fun bar() = fun named() {} +fun bar() = fun named() {} fun run(block: () -> T): T = null!! fun run2(block: () -> Unit): Unit = null!! diff --git a/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt index d13b99a1d75..5749a58884f 100644 --- a/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/enum/NonPrivateConstructor.fir.kt @@ -1,7 +1,7 @@ -enum class E public constructor(val x: Int) { +enum class E public constructor(val x: Int) { FIRST(); - internal constructor(): this(42) + internal constructor(): this(42) constructor(y: Int, z: Int): this(y + z) } diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt index aabfd382177..36981a1a7bb 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt @@ -5,5 +5,5 @@ fun foo() { fun A.foo() {} (fun A.foo() {}) - run(fun foo() {}) + run(fun foo() {}) } diff --git a/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt index 6ab4f630bac..4c4c44c2141 100644 --- a/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/intValuesOutOfRange.fir.kt @@ -6,12 +6,12 @@ fun foo(i: Int) = i fun bar(l: Long) = l fun main() { - val i = 111111111111111777777777777777 + val i = 111111111111111777777777777777 //todo add diagnostic text messages //report only 'The value is out of range' //not 'An integer literal does not conform to the expected type Int/Long' - val l: Long = 1111111111111117777777777777777 - foo(11111111111111177777777777777) - bar(11111111111111177777777777777) + val l: Long = 1111111111111117777777777777777 + foo(11111111111111177777777777777) + bar(11111111111111177777777777777) } diff --git a/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt index b586bde97c7..4f0bc9ff038 100644 --- a/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorRem/remAndRemAssignAmbiguity.fir.kt @@ -8,5 +8,5 @@ operator fun RemAndRemAssign.remAssign(x: Int) {} fun test() { var c = RemAndRemAssign - c %= 1 + c %= 1 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt index 0d62f497bee..2fcd95faf7b 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/AssignOperatorAmbiguity.fir.kt @@ -11,7 +11,7 @@ fun test(m: MyInt) { m += m var i = 1 - i += 34 + i += 34 } diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt index eb54f01d26b..4063b709120 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnLocal.fir.kt @@ -9,5 +9,5 @@ fun test() { val c = C() c += "" var c1 = C() - c1 += "" + c1 += "" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt index c74f3a68210..fc1bb6297da 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnProperty.fir.kt @@ -15,5 +15,5 @@ fun test() { val c = C() c.c += "" var c1 = C1() - c1.c += "" + c1.c += "" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt index 341b70069f8..3133a7bf398 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt @@ -13,11 +13,11 @@ fun box() : Boolean { var c = A() val d = c; c %= A(); - return (c != d) && (c.p = "yeah") + return (c != d) && (c.p = "yeah") } fun box2() : Boolean { var c = A() - return (c.p = "yeah") && true + return (c.p = "yeah") && true } diff --git a/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt b/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt index 56541013112..e6e1f2e7bc5 100644 --- a/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.fir.kt @@ -1,7 +1,7 @@ -sealed class Sealed protected constructor(val x: Int) { +sealed class Sealed protected constructor(val x: Int) { object FIRST : Sealed() - public constructor(): this(42) + public constructor(): this(42) constructor(y: Int, z: Int): this(y + z) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt index 0f1efb9a536..6de7a0bbdb8 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt @@ -1,17 +1,17 @@ object A { - constructor() + constructor() init {} } enum class B { X() { - constructor() + constructor() } } class C { companion object { - constructor() + constructor() } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt deleted file mode 100644 index 08d09a765ae..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -interface A { - constructor() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt index 2e0b7be2912..ba48f40c2ce 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface A { constructor() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt index 27ef5dbd823..f4d553bdfcb 100644 --- a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.fir.kt @@ -4,7 +4,7 @@ fun foo(x: Array, block: (T, Int) -> Int) { @Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int) // to prevent unused assignment diagnostic for the above statement - r.hashCode() + r.hashCode() var i = 1 diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt index 571ea9e70e1..41d54798b0a 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirBaseDiagnosticsTest.kt @@ -311,7 +311,7 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() { private fun Iterable>.toActualDiagnostic(root: PsiElement): List { val result = mutableListOf() - filter { it.factory != FirErrors.SYNTAX_ERROR }.mapTo(result) { + mapTo(result) { val oldDiagnostic = (it as FirPsiDiagnostic<*>).asPsiBasedDiagnostic() ActualDiagnostic(oldDiagnostic, null, true) }