From 363b25504d085ec0a47ea43e9362914d9981db09 Mon Sep 17 00:00:00 2001 From: Tianyu Geng Date: Fri, 24 Sep 2021 10:18:02 -0700 Subject: [PATCH] FIR checker: report REDUNDANT_LABEL_WARNING Since many labels are not present in the FIR tree, this checker is implemented as a syntax checker. Comparing with FE1.0, this change reports some REDUNDANT_LABEL_WARNING that FE1.0 has missed, especially LHS of assignments. --- .../diagnostics/KtFirDataClassConverters.kt | 7 + .../api/fir/diagnostics/KtFirDiagnostics.kt | 5 + .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 6 + .../diagnostics/FirDiagnosticsList.kt | 4 + .../fir/analysis/diagnostics/FirErrors.kt | 4 + .../checkers/CommonDeclarationCheckers.kt | 1 + .../syntax/FirRedundantLabelChecker.kt | 159 ++++++++++++++++++ .../diagnostics/FirDefaultErrorMessages.kt | 4 + .../LightTreePositioningStrategies.kt | 7 +- .../fir/declarations/utils/FirStatusUtils.kt | 13 +- .../diagnostics/tests/BreakContinue.fir.kt | 4 +- .../testData/diagnostics/tests/Casts.fir.kt | 23 --- compiler/testData/diagnostics/tests/Casts.kt | 1 + .../tests/FunctionCalleeExpressions.fir.kt | 2 +- .../diagnostics/tests/LValueAssignment.fir.kt | 36 ++-- .../tests/PackageInExpressionPosition.fir.kt | 2 +- .../diagnostics/tests/ReserveYield2.fir.kt | 4 +- .../diagnostics/tests/Underscore.fir.kt | 2 +- .../deadCode/commentsInDeadCode.fir.kt | 2 +- .../referenceToPropertyInitializer.fir.kt | 2 +- ...ueAndBreakLabelWithSameFunctionName.fir.kt | 2 +- .../notAFunctionLabel_after.fir.kt | 4 +- .../notAFunctionLabel_before.fir.kt | 4 +- .../controlStructures/redundantLabel.fir.kt | 39 ----- .../tests/controlStructures/redundantLabel.kt | 1 + .../labeledDelegatedExpression.fir.kt | 11 -- .../inference/labeledDelegatedExpression.kt | 1 + .../ParenthesizedVariable.fir.kt | 4 +- .../checkDeparenthesizedType.fir.kt | 10 +- .../deparenthesize/labeledSafeCall.fir.kt | 3 - .../tests/deparenthesize/labeledSafeCall.kt | 1 + .../functionAsExpression/WithoutBody.fir.kt | 2 +- .../return/IfWithoutElse.fir.kt | 2 +- .../expectedTypeFromCastParenthesized.fir.kt | 22 --- .../expectedTypeFromCastParenthesized.kt | 1 + .../diagnostics/tests/inline/labeled.fir.kt | 40 ----- .../diagnostics/tests/inline/labeled.kt | 1 + .../tests/inline/parenthesized.fir.kt | 27 --- .../diagnostics/tests/inline/parenthesized.kt | 1 + .../QualifiedExpressionNullability.fir.kt | 2 +- .../TypeMismatchOnUnaryOperations.fir.kt | 4 +- .../nestedCalls/argumentsInParentheses.fir.kt | 20 --- .../nestedCalls/argumentsInParentheses.kt | 1 + .../senselessComparison/parenthesized.fir.kt | 23 --- .../senselessComparison/parenthesized.kt | 1 + .../flowInlining/labeledReturns.fir.kt | 2 +- .../suspensionPointInMonitorNewInf.kt | 2 +- .../contractBuilder/common/neg/14.fir.kt | 2 +- 48 files changed, 255 insertions(+), 266 deletions(-) create mode 100644 compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirRedundantLabelChecker.kt delete mode 100644 compiler/testData/diagnostics/tests/Casts.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inline/labeled.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index cc50a6cbfaf..9e34d5d39e4 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -42,6 +42,7 @@ import org.jetbrains.kotlin.psi.KtExpressionWithLabel import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.KtIfExpression import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtLabelReferenceExpression import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration @@ -3744,6 +3745,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.REDUNDANT_LABEL_WARNING) { firDiagnostic -> + RedundantLabelWarningImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } add(FirJvmErrors.CONFLICTING_JVM_DECLARATIONS) { firDiagnostic -> ConflictingJvmDeclarationsImpl( firDiagnostic as FirPsiDiagnostic, diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt index ac2c736cc8a..95c3763d48a 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.psi.KtExpressionWithLabel import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.KtIfExpression import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtLabelReferenceExpression import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration @@ -2609,6 +2610,10 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = ReturnForBuiltInSuspend::class } + abstract class RedundantLabelWarning : KtFirDiagnostic() { + override val diagnosticClass get() = RedundantLabelWarning::class + } + abstract class ConflictingJvmDeclarations : KtFirDiagnostic() { override val diagnosticClass get() = ConflictingJvmDeclarations::class } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index e7771cad897..703645cd755 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -54,6 +54,7 @@ import org.jetbrains.kotlin.psi.KtExpressionWithLabel import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.KtIfExpression import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtLabelReferenceExpression import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration @@ -3148,6 +3149,11 @@ internal class ReturnForBuiltInSuspendImpl( override val token: ValidityToken, ) : KtFirDiagnostic.ReturnForBuiltInSuspend(), KtAbstractFirDiagnostic +internal class RedundantLabelWarningImpl( + override val firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.RedundantLabelWarning(), KtAbstractFirDiagnostic + internal class ConflictingJvmDeclarationsImpl( override val firDiagnostic: FirPsiDiagnostic, override val token: ValidityToken, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 1715861b594..95f06d573ed 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -1353,6 +1353,10 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { val MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND by error(PositioningStrategy.REFERENCED_NAME_BY_QUALIFIED) val RETURN_FOR_BUILT_IN_SUSPEND by error() } + + val LABEL by object : DiagnosticGroup("label") { + val REDUNDANT_LABEL_WARNING by warning(PositioningStrategy.LABEL) + } } private val exposedVisibilityDiagnosticInit: DiagnosticBuilder.() -> Unit = { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 56721271140..450f419e2b2 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -66,6 +66,7 @@ import org.jetbrains.kotlin.psi.KtExpressionWithLabel import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.KtIfExpression import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtLabelReferenceExpression import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration @@ -703,4 +704,7 @@ object FirErrors { val MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND by error0(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED) val RETURN_FOR_BUILT_IN_SUSPEND by error0() + // label + val REDUNDANT_LABEL_WARNING by warning0(SourceElementPositioningStrategies.LABEL) + } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonDeclarationCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonDeclarationCheckers.kt index e708abca6f8..c53b93cca35 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonDeclarationCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonDeclarationCheckers.kt @@ -30,6 +30,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() { FirInvalidAndDangerousCharactersChecker, FirAmbiguousAnonymousTypeChecker, FirExplicitApiDeclarationChecker, + FirRedundantLabelChecker, ) override val functionCheckers: Set diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirRedundantLabelChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirRedundantLabelChecker.kt new file mode 100644 index 00000000000..7e307159602 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirRedundantLabelChecker.kt @@ -0,0 +1,159 @@ +/* + * Copyright 2010-2021 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.syntax + +import com.intellij.lang.LighterASTNode +import com.intellij.openapi.util.Ref +import com.intellij.psi.PsiElement +import com.intellij.util.diff.FlyweightCapableTreeStructure +import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.descriptors.EffectiveVisibility +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.analysis.buildChildSourceElement +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol +import org.jetbrains.kotlin.fir.analysis.diagnostics.* +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility +import org.jetbrains.kotlin.fir.expressions.FirBlock +import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.psi.* + +object FirRedundantLabelChecker : FirDeclarationSyntaxChecker() { + override fun checkLightTree( + element: FirDeclaration, + source: FirLightSourceElement, + context: CheckerContext, + reporter: DiagnosticReporter + ) { + // Local declarations are already checked when the containing declaration is checked. + if (!isRootLabelContainer(element)) return + + val allTraversalRoots = mutableSetOf() + + // First collect all labels in the declaration + element.accept(object : FirVisitorVoid() { + override fun visitElement(element: FirElement) { + element.acceptChildren(this) + } + + override fun visitBlock(block: FirBlock) { + markTraversalRoot(block) + super.visitBlock(block) + } + + override fun visitProperty(property: FirProperty) { + markTraversalRoot(property) + super.visitProperty(property) + } + + override fun visitSimpleFunction(simpleFunction: FirSimpleFunction) { + markTraversalRoot(simpleFunction) + super.visitFunction(simpleFunction) + } + + override fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor) { + markTraversalRoot(propertyAccessor) + super.visitPropertyAccessor(propertyAccessor) + } + + override fun visitConstructor(constructor: FirConstructor) { + markTraversalRoot(constructor) + super.visitConstructor(constructor) + } + + private fun markTraversalRoot(elem: FirElement) { + val elemSource = elem.source + if (elemSource?.kind is FirRealSourceElementKind) { + allTraversalRoots.add(elemSource) + } + } + }) + + for (root in allTraversalRoots) { + root.treeStructure.reportRedundantLabels(reporter, context, root as FirLightSourceElement, allTraversalRoots) + } + } + + private fun FlyweightCapableTreeStructure.reportRedundantLabels( + reporter: DiagnosticReporter, + context: CheckerContext, + source: FirLightSourceElement, + allTraversalRoots: Set, + isChildNode: Boolean = false, + ) { + if (isChildNode && source in allTraversalRoots) return // Prevent double traversal + val node = source.lighterASTNode + if (node.tokenType == KtNodeTypes.LABELED_EXPRESSION) { + val labelQualifier = findChildByType(node, KtNodeTypes.LABEL_QUALIFIER) + if (labelQualifier != null) { + findChildByType(labelQualifier, KtNodeTypes.LABEL)?.let { labelNode -> + when (unwrapParenthesesLabelsAndAnnotations(node).tokenType) { + KtNodeTypes.LAMBDA_EXPRESSION, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE, KtNodeTypes.FUN -> {} + else -> reporter.reportOn( + source.buildChildSourceElement(labelNode), + FirErrors.REDUNDANT_LABEL_WARNING, + context + ) + } + } + } + } + val childrenRef = Ref.create>(null) + getChildren(node, childrenRef) + for (child in childrenRef.get() ?: return) { + if (child == null) continue + reportRedundantLabels(reporter, context, source.buildChildSourceElement(child), allTraversalRoots, true) + } + } + + override fun checkPsi( + element: FirDeclaration, + source: FirPsiSourceElement, + psi: PsiElement, + context: CheckerContext, + reporter: DiagnosticReporter + ) { + // Local declarations are already checked when the containing declaration is checked. + if (!isRootLabelContainer(element)) return + + // First collect all labels in the declaration + source.psi.accept(object : KtTreeVisitorVoid() { + override fun visitLabeledExpression(expression: KtLabeledExpression) { + val labelNameExpression = expression.getTargetLabel() + + if (labelNameExpression != null) { + val deparenthesizedBaseExpression = KtPsiUtil.deparenthesize(expression) + if (deparenthesizedBaseExpression !is KtLambdaExpression && + deparenthesizedBaseExpression !is KtLoopExpression && + deparenthesizedBaseExpression !is KtNamedFunction + ) { + reporter.reportOn(labelNameExpression.toFirPsiSourceElement(), FirErrors.REDUNDANT_LABEL_WARNING, context) + } + } + super.visitLabeledExpression(expression) + } + }) + } + + private fun isRootLabelContainer(element: FirDeclaration): Boolean { + if (element.source?.kind is FirFakeSourceElementKind) return false + if (element is FirCallableDeclaration && element.effectiveVisibility == EffectiveVisibility.Local) return false + return when (element) { + is FirAnonymousFunction -> false + is FirFunction -> true + is FirProperty -> true + // Consider class initializer of non local class as root label container. + is FirAnonymousInitializer -> { + val parentVisibility = + (element.getContainingClassSymbol(element.moduleData.session) as? FirRegularClassSymbol)?.effectiveVisibility + parentVisibility != null && parentVisibility != EffectiveVisibility.Local + } + else -> 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 881c513b263..c91c8a4c03d 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 @@ -382,6 +382,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_CALL_OF import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_EXPLICIT_BACKING_FIELD import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_EXPLICIT_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_LABEL_WARNING import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_MODALITY_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_MODIFIER_FOR_TARGET @@ -1760,6 +1761,9 @@ class FirDefaultErrorMessages { ) map.put(RETURN_FOR_BUILT_IN_SUSPEND, "Using implicit label for this lambda is prohibited") + // Label + map.put(REDUNDANT_LABEL_WARNING, "Label is redundant, because it can not be referenced in either ''break'', ''continue'', or ''return'' expression") + // Extended checkers group map.put(REDUNDANT_VISIBILITY_MODIFIER, "Redundant visibility modifier") map.put(REDUNDANT_MODALITY_MODIFIER, "Redundant modality modifier") diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt index c36411ff39c..9fc4d9a97a2 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/LightTreePositioningStrategies.kt @@ -518,7 +518,7 @@ object LightTreePositioningStrategies { ) { val lhs = tree.firstChildExpression(node) lhs?.let { - tree.unwrapParenthesesLabelsAndAnnotations(it)?.let { unwrapped -> + tree.unwrapParenthesesLabelsAndAnnotations(it).let { unwrapped -> return markElement(unwrapped, startOffset, endOffset, tree, node) } } @@ -880,7 +880,7 @@ object LightTreePositioningStrategies { tree.firstChildExpression(node) } lhs?.let { - tree.unwrapParenthesesLabelsAndAnnotations(it)?.let { unwrapped -> + tree.unwrapParenthesesLabelsAndAnnotations(it).let { unwrapped -> return markElement(unwrapped, startOffset, endOffset, tree, node) } } @@ -1153,8 +1153,7 @@ private fun FlyweightCapableTreeStructure.referenceExpression( } return result } - -private fun FlyweightCapableTreeStructure.unwrapParenthesesLabelsAndAnnotations(node: LighterASTNode): LighterASTNode? { +fun FlyweightCapableTreeStructure.unwrapParenthesesLabelsAndAnnotations(node: LighterASTNode): LighterASTNode { var unwrapped = node while (true) { unwrapped = when (unwrapped.tokenType) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt index 46d81c3ed88..55b1d256426 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt @@ -6,12 +6,7 @@ package org.jetbrains.kotlin.fir.declarations.utils import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.fir.FirRenderer import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl -import org.jetbrains.kotlin.fir.render -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract inline val FirMemberDeclaration.modality: Modality? get() = status.modality inline val FirMemberDeclaration.isAbstract: Boolean get() = status.modality == Modality.ABSTRACT @@ -24,9 +19,13 @@ inline val FirMemberDeclaration.isFinal: Boolean } inline val FirMemberDeclaration.visibility: Visibility get() = status.visibility + +/** + * Gets the effective visibility. Note that it's assumed that the element or its non-local container has at least resolve phase + * [FirResolvePhase.STATUS], in which case, any declarations with unresolved status are effectively local. + */ inline val FirMemberDeclaration.effectiveVisibility: EffectiveVisibility - get() = (status as? FirResolvedDeclarationStatus)?.effectiveVisibility - ?: error("Effective visibility for ${render(FirRenderer.RenderMode.NoBodies)} must be resolved") + get() = (status as? FirResolvedDeclarationStatus)?.effectiveVisibility ?: EffectiveVisibility.Local inline val FirMemberDeclaration.allowsToHaveFakeOverride: Boolean get() = !Visibilities.isPrivate(visibility) && visibility != Visibilities.InvisibleFake diff --git a/compiler/testData/diagnostics/tests/BreakContinue.fir.kt b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt index 469ac667bd4..4a2a4abb85c 100644 --- a/compiler/testData/diagnostics/tests/BreakContinue.fir.kt +++ b/compiler/testData/diagnostics/tests/BreakContinue.fir.kt @@ -2,7 +2,7 @@ class C { fun f (a : Boolean, b : Boolean) { b@ while (true) - a@ { + a@ { break@f break break@b @@ -12,7 +12,7 @@ class C { continue b@ while (true) - a@ { + a@ { continue@f continue continue@b diff --git a/compiler/testData/diagnostics/tests/Casts.fir.kt b/compiler/testData/diagnostics/tests/Casts.fir.kt deleted file mode 100644 index 9c1a5774b9a..00000000000 --- a/compiler/testData/diagnostics/tests/Casts.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// !CHECK_TYPE - -fun test() : Unit { - var x : Int? = 0 - var y : Int = 0 - - checkSubtype(x) - checkSubtype(y) - checkSubtype(x as Int) - checkSubtype(y as Int) - checkSubtype(x as Int?) - checkSubtype(y as Int?) - checkSubtype(x as? Int) - checkSubtype(y as? Int) - checkSubtype(x as? Int?) - checkSubtype(y as? Int?) - - val s = "" as Any - ("" as String?)?.length - (data@("" as String?))?.length - (@MustBeDocumented()( "" as String?))?.length - Unit -} diff --git a/compiler/testData/diagnostics/tests/Casts.kt b/compiler/testData/diagnostics/tests/Casts.kt index 4c2b4a990f0..68bafad7f3c 100644 --- a/compiler/testData/diagnostics/tests/Casts.kt +++ b/compiler/testData/diagnostics/tests/Casts.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE fun test() : Unit { diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt index 353483534e4..1f1812d686f 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt @@ -62,7 +62,7 @@ fun main1() { {1}(); (fun (x : Int) = x)(1) 1.(fun Int.(x : Int) = x)(1); - l@{1}() + l@{1}() 1.((fun Int.() = 1))() 1.(f())() 1.if(true){f()}else{f()}() diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt index 66d2a62cf01..78850380657 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.fir.kt @@ -57,19 +57,19 @@ annotation class Ann 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 @Ann - l@ (i) = 123 + l@ (i) = 123 } fun canBe2(j: Int) { - (label@ j) = 34 + (label@ j) = 34 } class A() { @@ -79,29 +79,29 @@ class A() { class Test() { fun testIllegalValues() { 1 += 23 - (l@ 1) += 23 + (l@ 1) += 23 getInt() += 343 - (f@ getInt()) += 343 + (f@ getInt()) += 343 1++ - (r@ 1)-- + (r@ 1)-- getInt()++ - (m@ getInt())-- + (m@ getInt())-- ++2 - --(r@ 2) + --(r@ 2) this++ var s : String = "r" s += "ss" s += this - s += (a@ 2) + s += (a@ 2) @Ann - l@ (1) = 123 + l@ (1) = 123 } fun testIncompleteSyntax() { @@ -114,22 +114,22 @@ class Test() { val b: Int = 34 a += 34 - (l@ a) += 34 + (l@ a) += 34 b += 34 a++ - (@Ann l@ a)-- + (@Ann l@ a)-- (a)++ --a - ++(@Ann l@ a) + ++(@Ann l@ a) --(a) } fun testVariables1() { val b: Int = 34 - (l@ b) += 34 + (l@ b) += 34 //repeat for b (b) += 3 } @@ -140,12 +140,12 @@ class Test() { a[6] += 43 @Ann a[7] = 7 - (@Ann l@ (a))[8] = 8 + (@Ann l@ (a))[8] = 8 ab.getArray()[54] = 23 ab.getArray()[54]++ - (f@ a)[3] = 4 + (f@ a)[3] = 4 this[54] = 34 } diff --git a/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt index 11456837617..1d339cd44cb 100644 --- a/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt +++ b/compiler/testData/diagnostics/tests/PackageInExpressionPosition.fir.kt @@ -22,6 +22,6 @@ fun main() { System is Int System() (System) - foo@ System + foo@ System null in System } diff --git a/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt b/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt index aab3b906def..e9547cd0637 100644 --- a/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt +++ b/compiler/testData/diagnostics/tests/ReserveYield2.fir.kt @@ -5,8 +5,8 @@ annotation class yield fun bar(p: Int) { - yield@ p - `yield`@ p + yield@ p + `yield`@ p @yield() p @`yield`() p diff --git a/compiler/testData/diagnostics/tests/Underscore.fir.kt b/compiler/testData/diagnostics/tests/Underscore.fir.kt index 1e961ffffc7..6edbde47123 100644 --- a/compiler/testData/diagnostics/tests/Underscore.fir.kt +++ b/compiler/testData/diagnostics/tests/Underscore.fir.kt @@ -21,7 +21,7 @@ fun __(___: Int, y: _: String) = 1 - __@ return if (y != null) __(____, y) else __(`_`, ______) + __@ return if (y != null) __(____, y) else __(`_`, ______) } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt index 7e3230febec..8f44fcbe1e8 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.fir.kt @@ -12,7 +12,7 @@ fun test2() { bar(11, todo()/*comment1*/, ""/*comment2*/) } fun test3() { - bar(11, l@(todo()/*comment*/), "") + bar(11, l@(todo()/*comment*/), "") } fun todo(): Nothing = throw Exception() diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt index 293091f3571..9662d4c4982 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.fir.kt @@ -19,7 +19,7 @@ class TestObjectLiteral { val y = obj } } - val obj1: A = l@ ( object: A(obj1) { + val obj1: A = l@ ( object: A(obj1) { init { val x = obj1 } diff --git a/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt index b2d5f04a659..2d1eeacf1d6 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/continueAndBreakLabelWithSameFunctionName.fir.kt @@ -50,4 +50,4 @@ class Test7 { break@Test8 } } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt index c5e6fe20f02..f966a8b3c6b 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_after.fir.kt @@ -51,12 +51,12 @@ fun testLoopLabelInReturn(xs: List) { } fun testValLabelInReturn() { - L@ val fn = { return@L } + L@ val fn = { return@L } fn() } fun testHighOrderFunctionCallLabelInReturn() { - L@ run { + L@ run { return@L } } diff --git a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt index 237beb97d69..ca00dc6c1f1 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/notAFunctionLabel_before.fir.kt @@ -51,12 +51,12 @@ fun testLoopLabelInReturn(xs: List) { } fun testValLabelInReturn() { - L@ val fn = { return@L } + L@ val fn = { return@L } fn() } fun testHighOrderFunctionCallLabelInReturn() { - L@ run { + L@ run { return@L } } diff --git a/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt deleted file mode 100644 index 1b23784d271..00000000000 --- a/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.fir.kt +++ /dev/null @@ -1,39 +0,0 @@ -@Target(AnnotationTarget.EXPRESSION) -@Retention(AnnotationRetention.SOURCE) -annotation class Ann - -fun testLambdaLabel() = l@ { 42 } - -fun testAnonymousFunctionLabel() = l@ fun() {} - -fun testAnnotatedLambdaLabel() = lambda@ @Ann {} - -fun testParenthesizedLambdaLabel() = lambda@ ( {} ) - -fun testLabelBoundToInvokeOperatorExpression() = l@ { 42 }() - -fun testLabelBoundToLambda() = (l@ { 42 })() - -fun testWhileLoopLabel() { - L@ while (true) {} -} - -fun testDoWhileLoopLabel() { - L@ do {} while (true) -} - -fun testForLoopLabel(xs: List) { - L@ for (x in xs) {} -} - -fun testValLabel() { - L@ val fn = {} - fn() -} - -fun testHighOrderFunctionCallLabel() { - L@ run {} -} - -fun testAnonymousObjectLabel() = - L@ object {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.kt b/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.kt index 06267698864..7d7aeb6c6c8 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/redundantLabel.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Target(AnnotationTarget.EXPRESSION) @Retention(AnnotationRetention.SOURCE) annotation class Ann diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt deleted file mode 100644 index f8290772eae..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -import kotlin.reflect.KProperty - -class A3 { - val a: String by l@ MyProperty() - - class MyProperty {} - - operator fun MyProperty.getValue(thisRef: Any?, desc: KProperty<*>): T { - throw Exception("$thisRef $desc") - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.kt index e5b1e6b3584..975a9b4d92f 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/labeledDelegatedExpression.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL import kotlin.reflect.KProperty class A3 { diff --git a/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt index f8950a03263..c0535e51ccb 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt +++ b/compiler/testData/diagnostics/tests/deparenthesize/ParenthesizedVariable.fir.kt @@ -1,3 +1,3 @@ fun test() { - (d@ val bar = 2) -} \ No newline at end of file + (d@ val bar = 2) +} diff --git a/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt index 7c9c6f68318..8e760dfae71 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt +++ b/compiler/testData/diagnostics/tests/deparenthesize/checkDeparenthesizedType.fir.kt @@ -6,19 +6,19 @@ import checkSubtype fun test(i: Int?) { if (i != null) { - foo(l1@ i) + foo(l1@ i) foo((i)) - foo(l2@ (i)) - foo((l3@ i)) + foo(l2@ (i)) + foo((l3@ i)) } - val a: Int = l4@ "" + val a: Int = l4@ "" val b: Int = ("") val c: Int = checkSubtype("") val d: Int = checkSubtype("") - foo(l4@ "") + foo(l4@ "") foo(("")) foo(checkSubtype("")) foo(checkSubtype("")) diff --git a/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt b/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt deleted file mode 100644 index e270df0ec1d..00000000000 --- a/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun f(s : String?) : Boolean { - return foo@(s?.equals("a"))!! -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.kt b/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.kt index a9e8b9255bc..40fe7628a75 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.kt +++ b/compiler/testData/diagnostics/tests/deparenthesize/labeledSafeCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun f(s : String?) : Boolean { return foo@(s?.equals("a"))!! } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt index ccb1f2408b2..d8a201054d3 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithoutBody.fir.kt @@ -9,4 +9,4 @@ fun outer() { bar(fun ()) bar(l@ fun ()) bar(@ann fun ()) -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt index cf5888dab3d..c24cb24c35b 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.fir.kt @@ -12,4 +12,4 @@ val b/*: () -> Int */ = l@ { val c/*: () -> Unit */ = l@ { if (flag) 4 -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt deleted file mode 100644 index 2fcb8d78216..00000000000 --- a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -// !LANGUAGE: +ExpectedTypeFromCast - -@Target(AnnotationTarget.EXPRESSION) -@Retention(AnnotationRetention.SOURCE) -annotation class bar - -fun foo(): T = TODO() - -fun id(value: V) = value - -val par1 = (foo()) as String -val par2 = ((foo())) as String - -val par3 = (dd@ (foo())) as String - -val par4 = ( @bar() (foo())) as String - -object X { - fun foo(): T = TODO() -} - -val par5 = ( @bar() X.foo()) as String diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt index 471612aaaf8..50782e4a3e7 100644 --- a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCastParenthesized.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ExpectedTypeFromCast @Target(AnnotationTarget.EXPRESSION) diff --git a/compiler/testData/diagnostics/tests/inline/labeled.fir.kt b/compiler/testData/diagnostics/tests/inline/labeled.fir.kt deleted file mode 100644 index 15f37ccad45..00000000000 --- a/compiler/testData/diagnostics/tests/inline/labeled.fir.kt +++ /dev/null @@ -1,40 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE - -inline fun foo(bar1: (String.() -> Int) -> Int, bar2: (()->Int) -> Int) { - bar1 label@ { - this@label.length - } - - bar1 { - this.length - } - //unmute after KT-4247 fix - //bar1 { - // this@bar1.length - //} - - bar2 l@ { - 11 - } - - bar2 { - 12 - } - -} - -inline fun foo2(bar1: (String.() -> Int) -> Int) { - l1@ bar1 - - l2@ bar1 { - 11 - } - - (l3@ bar1) { - 11 - } - - (l5@ (l4@ bar1)) { - 11 - } -} diff --git a/compiler/testData/diagnostics/tests/inline/labeled.kt b/compiler/testData/diagnostics/tests/inline/labeled.kt index fa36e7540bd..986f5921a04 100644 --- a/compiler/testData/diagnostics/tests/inline/labeled.kt +++ b/compiler/testData/diagnostics/tests/inline/labeled.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE inline fun foo(bar1: (String.() -> Int) -> Int, bar2: (()->Int) -> Int) { diff --git a/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt b/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt deleted file mode 100644 index 49451133b4c..00000000000 --- a/compiler/testData/diagnostics/tests/inline/parenthesized.fir.kt +++ /dev/null @@ -1,27 +0,0 @@ -// !CHECK_TYPE - -inline fun inlineFunWithInvoke(s: (p: Int) -> Unit) { - (s)(11) - (s).invoke(11) - (s) invoke 11 - (s) -} - -inline fun Function1.inlineExt() { - (this).invoke(11) - (this) invoke 11 - (this)(11) - (this) -} - -inline fun inlineFunWithInvoke2(s: (p: Int) -> Unit) { - (((s)))(11) - (((s))).invoke(11) - (((s))) invoke 11 - (((s))) -} - -inline fun propagation(s: (p: Int) -> Unit) { - inlineFunWithInvoke((label@ s)) - inlineFunWithInvoke((label2@ label@ s)) -} diff --git a/compiler/testData/diagnostics/tests/inline/parenthesized.kt b/compiler/testData/diagnostics/tests/inline/parenthesized.kt index b12d7d414d0..e42d2a33402 100644 --- a/compiler/testData/diagnostics/tests/inline/parenthesized.kt +++ b/compiler/testData/diagnostics/tests/inline/parenthesized.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE inline fun inlineFunWithInvoke(s: (p: Int) -> Unit) { diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt index 6916a5d33c3..16dc3de9483 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/QualifiedExpressionNullability.fir.kt @@ -32,7 +32,7 @@ fun main() { val w: Foo? = null w.f = z (w.f) = z - (label@ w.f) = z + (label@ w.f) = z w!!.f = z w.f = z w!!.f = z diff --git a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt index d9cbd608db7..b03d15a42fd 100644 --- a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.fir.kt @@ -8,8 +8,8 @@ fun main() { val h : String = v--; val h1 : String = --v; val i : String = !true; - val j : String = foo@ true; - val k : String = foo@ bar@ true; + val j : String = foo@ true; + val k : String = foo@ bar@ true; val l : String = -1; val m : String = +1; } diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt deleted file mode 100644 index 1ffa3472243..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -interface Foo - -class Bar { - operator fun invoke(): Foo = throw Exception() -} - -class A { - val bar = Bar() -} - -fun fooInt(l: Foo) = l - -fun test(bar: Bar, a: A) { - // no elements with error types - fooInt((bar())) - fooInt(if (true) bar() else bar()) - fooInt(label@ bar()) - fooInt(a.bar()) - fooInt(((label@ if (true) (a.bar()) else bar()))) -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.kt index aab2243f1d5..74973e41072 100644 --- a/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.kt +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/argumentsInParentheses.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface Foo class Bar { diff --git a/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt b/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt deleted file mode 100644 index 15c100df48d..00000000000 --- a/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -fun testEquals(x: Int) { - if (x == null) {} - if (x == (null)) {} - if (x == foo@ null) {} -} - -fun testEqualsFlipped(x: Int) { - if (null == x) {} - if ((null) == x) {} - if (foo@ null == x) {} -} - -fun testNotEquals(x: Int) { - if (x != null) {} - if (x != (null)) {} - if (x != foo@ null) {} -} - -fun testNotEqualsFlipped(x: Int) { - if (null != x) {} - if ((null) != x) {} - if (foo@ null != x) {} -} diff --git a/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.kt b/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.kt index 1c8ae0da59f..838097ad29d 100644 --- a/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.kt +++ b/compiler/testData/diagnostics/tests/senselessComparison/parenthesized.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun testEquals(x: Int) { if (x == null) {} if (x == (null)) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt index 883aa5c5f62..5b8d61163d1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/controlflow/flowInlining/labeledReturns.fir.kt @@ -83,4 +83,4 @@ fun threeLevelsReturnWithUnknown(x: Int?): Int? { } } return y.inc() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.kt index 5f91bdbd2fb..1a893309818 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspensionPointInMonitorNewInf.kt @@ -59,4 +59,4 @@ suspend fun ifWhenAndOtherNonsence() { } } -suspend fun returnsInt(): Int = 0 \ No newline at end of file +suspend fun returnsInt(): Int = 0 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/14.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/14.fir.kt index 78c15773f00..7c53cd6a78f 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/14.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/14.fir.kt @@ -31,7 +31,7 @@ inline fun case_4(block: () -> Unit) { // TESTCASE NUMBER: 5 inline fun case_5(block: () -> Unit) { - test@ contract { + test@ contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return block()