From 8f333aef3a569fb95432b3fba027c141aaf0bde3 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 28 Sep 2020 13:40:36 +0300 Subject: [PATCH] Introduce warning about forbidden referencing to underscore named parameter of the catch block in a future release (KT-31567) --- ...irOldFrontendDiagnosticsTestGenerated.java | 10 ++++ .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../resolve/PlatformConfiguratorBase.kt | 3 +- ...rscoreNamedParameterOfCatchBlockChecker.kt | 49 ++++++++++++++++ .../resolve/calls/tower/PSICallResolver.kt | 7 ++- .../org/jetbrains/kotlin/psi/KtParameter.java | 4 ++ .../jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt | 3 + .../resolve/underscoreInCatchBlock.fir.kt | 57 +++++++++++++++++++ .../tests/resolve/underscoreInCatchBlock.kt | 57 +++++++++++++++++++ .../tests/resolve/underscoreInCatchBlock.txt | 3 + ...scoreInCatchBlockWithEnabledFeature.fir.kt | 57 +++++++++++++++++++ ...nderscoreInCatchBlockWithEnabledFeature.kt | 57 +++++++++++++++++++ ...derscoreInCatchBlockWithEnabledFeature.txt | 3 + .../checkers/DiagnosticsTestGenerated.java | 10 ++++ .../DiagnosticsUsingJavacTestGenerated.java | 10 ++++ .../kotlin/config/LanguageVersionSettings.kt | 1 + .../kotlin/resolve/DescriptorUtils.kt | 3 + 18 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ReferencingToUnderscoreNamedParameterOfCatchBlockChecker.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.fir.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.txt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 8e01e1056d8..6d23a13afe1 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -19197,6 +19197,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.kt"); } + @TestMetadata("underscoreInCatchBlock.kt") + public void testUnderscoreInCatchBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt"); + } + + @TestMetadata("underscoreInCatchBlockWithEnabledFeature.kt") + public void testUnderscoreInCatchBlockWithEnabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt"); + } + @TestMetadata("wrongNumberOfTypeArguments.kt") public void testWrongNumberOfTypeArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 96e38e08df0..62c992e8667 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -889,6 +889,7 @@ public interface Errors { DiagnosticFactory1 YIELD_IS_RESERVED = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 UNDERSCORE_IS_RESERVED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNDERSCORE_USAGE_WITHOUT_BACKTICKS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER = DiagnosticFactory0.create(WARNING); DiagnosticFactory1 INVALID_CHARACTERS = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 INAPPLICABLE_OPERATOR_MODIFIER = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 94a35b51afa..00b2efff57c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -509,6 +509,7 @@ public class DefaultErrorMessages { MAP.put(UNDERSCORE_IS_RESERVED, "Names _, __, ___, ..., are reserved in Kotlin"); MAP.put(UNDERSCORE_USAGE_WITHOUT_BACKTICKS, "Names _, __, ___, ... can be used only in back-ticks (`_`, `__`, `___`, ...)"); + MAP.put(RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER, "Referencing to an underscore-named parameter is deprecated. It will be an error in a future release."); MAP.put(YIELD_IS_RESERVED, "{0}", STRING); MAP.put(INVALID_CHARACTERS, "Name {0}", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index 78d6cb3c058..f9bb124fc19 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -54,7 +54,8 @@ private val DEFAULT_CALL_CHECKERS = listOf( UselessElvisCallChecker(), ResultTypeWithNullableOperatorsChecker(), NullableVarargArgumentCallChecker, NamedFunAsExpressionChecker, ContractNotAllowedCallChecker, ReifiedTypeParameterSubstitutionChecker(), MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker, SuspendConversionCallChecker, - UnitConversionCallChecker, FunInterfaceConstructorReferenceChecker, NullableExtensionOperatorWithSafeCallChecker + UnitConversionCallChecker, FunInterfaceConstructorReferenceChecker, NullableExtensionOperatorWithSafeCallChecker, + ReferencingToUnderscoreNamedParameterOfCatchBlockChecker ) private val DEFAULT_TYPE_CHECKERS = emptyList() private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ReferencingToUnderscoreNamedParameterOfCatchBlockChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ReferencingToUnderscoreNamedParameterOfCatchBlockChecker.kt new file mode 100644 index 00000000000..db223e02349 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ReferencingToUnderscoreNamedParameterOfCatchBlockChecker.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2019 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.resolve.calls.checkers + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType +import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce +import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnceWrtDiagnosticFactoryList +import org.jetbrains.kotlin.psi.KtNameReferenceExpression +import org.jetbrains.kotlin.psi.KtParameter +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.calls.SPECIAL_FUNCTION_NAMES +import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.* +import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl +import org.jetbrains.kotlin.resolve.calls.tower.psiCallArgument +import org.jetbrains.kotlin.resolve.calls.tower.psiExpression +import org.jetbrains.kotlin.resolve.calls.tower.psiKotlinCall +import org.jetbrains.kotlin.resolve.descriptorUtil.isUnderscoreNamed +import org.jetbrains.kotlin.resolve.source.KotlinSourceElement +import org.jetbrains.kotlin.types.DeferredType +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.typeUtil.isNothing +import org.jetbrains.kotlin.types.typeUtil.isNothingOrNullableNothing +import org.jetbrains.kotlin.types.typeUtil.isTypeParameter + +object ReferencingToUnderscoreNamedParameterOfCatchBlockChecker : CallChecker { + override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { + val descriptor = resolvedCall.resultingDescriptor + + if (descriptor !is LocalVariableDescriptor || !descriptor.isUnderscoreNamed) return + + val sourceElement = descriptor.source as? KotlinSourceElement ?: return + val ktParameter = sourceElement.psi as? KtParameter ?: return + + if (ktParameter.isCatchParameter) { + context.trace.reportDiagnosticOnce(Errors.RESOLVED_TO_UNDERSCORE_NAMED_CATCH_PARAMETER.on(reportOn)) + } + } +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 87ffd0112e5..d73b00e502c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns +import org.jetbrains.kotlin.resolve.descriptorUtil.isUnderscoreNamed import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.receivers.* import org.jetbrains.kotlin.types.* @@ -837,7 +838,11 @@ class PSICallResolver( val catchScope = with(scope) { LexicalWritableScope(this, ownerDescriptor, false, redeclarationChecker, LexicalScopeKind.CATCH) } - catchScope.addVariableDescriptor(variableDescriptor) + val isReferencingToUnderscoreNamedParameterForbidden = + languageVersionSettings.getFeatureSupport(LanguageFeature.ForbidReferencingToUnderscoreNamedParameterOfCatchBlock) == LanguageFeature.State.ENABLED + if (!variableDescriptor.isUnderscoreNamed || !isReferencingToUnderscoreNamedParameterForbidden) { + catchScope.addVariableDescriptor(variableDescriptor) + } return replaceScope(catchScope) } } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtParameter.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtParameter.java index 0b0eb16837f..d7f191b7e1a 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtParameter.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtParameter.java @@ -140,6 +140,10 @@ public class KtParameter extends KtNamedDeclarationStub imp return getParent() instanceof KtForExpression; } + public boolean isCatchParameter() { + return getParent().getParent() instanceof KtCatchClause; + } + @Nullable @Override public KtParameterList getValueParameterList() { diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 8976aa93173..269f211c79c 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -673,3 +673,6 @@ fun getTrailingCommaByElementsList(elementList: PsiElement?): PsiElement? { val lastChild = elementList?.lastChild?.let { if (it !is PsiComment) it else it.getPrevSiblingIgnoringWhitespaceAndComments() } return lastChild?.takeIf { it.node.elementType == KtTokens.COMMA } } + +val KtNameReferenceExpression.isUnderscoreInBackticks + get() = getReferencedName() == "`_`" diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt new file mode 100644 index 00000000000..b18df6f1a3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: -ForbidReferencingToUnderscoreNamedParameterOfCatchBlock +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION + +fun foo() { + try { + TODO() + } catch (_: Exception) { + `_`.stackTrace + } + try { + TODO() + } catch (_: Exception) { + val x = { + val x2 = { + val x3 = { y: Int -> + val x4 = { _: Int -> + `_` + } + `_` + } + `_` + 10 + } + fun bar(x: Exception = `_`) {} + class Bar(`_`: Exception = `_`) { + inner class Bar2(x: Exception = `_`) { } + } + } + } catch (_: Exception) { + `_`.stackTrace + val y1 = _ + val y2 = (`_`) + } + try { + TODO() + } catch (_: Exception) { + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo1 = { `_`: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo2 = { _: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt new file mode 100644 index 00000000000..6d323b996dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: -ForbidReferencingToUnderscoreNamedParameterOfCatchBlock +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION + +fun foo() { + try { + TODO() + } catch (_: Exception) { + `_`.stackTrace + } + try { + TODO() + } catch (_: Exception) { + val x = { + val x2 = { + val x3 = { y: Int -> + val x4 = { _: Int -> + `_` + } + `_` + } + `_` + 10 + } + fun bar(x: Exception = `_`) {} + class Bar(`_`: Exception = `_`) { + inner class Bar2(x: Exception = `_`) { } + } + } + } catch (_: Exception) { + `_`.stackTrace + val y1 = _ + val y2 = (`_`) + } + try { + TODO() + } catch (_: Exception) { + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo1 = { `_`: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo2 = { _: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.txt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.txt new file mode 100644 index 00000000000..65a6ac47e1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.txt @@ -0,0 +1,3 @@ +package + +public fun foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.fir.kt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.fir.kt new file mode 100644 index 00000000000..8b52f9445b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +ForbidReferencingToUnderscoreNamedParameterOfCatchBlock +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION + +fun foo() { + try { + TODO() + } catch (_: Exception) { + `_`.stackTrace + } + try { + TODO() + } catch (_: Exception) { + val x = { + val x2 = { + val x3 = { y: Int -> + val x4 = { _: Int -> + `_` + } + `_` + } + `_` + 10 + } + fun bar(x: Exception = `_`) {} + class Bar(`_`: Exception = `_`) { + inner class Bar2(x: Exception = `_`) { } + } + } + } catch (_: Exception) { + `_`.stackTrace + val y1 = _ + val y2 = (`_`) + } + try { + TODO() + } catch (_: Exception) { + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo1 = { `_`: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo2 = { _: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt new file mode 100644 index 00000000000..828d1a518e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +ForbidReferencingToUnderscoreNamedParameterOfCatchBlock +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION + +fun foo() { + try { + TODO() + } catch (_: Exception) { + `_`.stackTrace + } + try { + TODO() + } catch (_: Exception) { + val x = { + val x2 = { + val x3 = { y: Int -> + val x4 = { _: Int -> + `_` + } + `_` + } + `_` + 10 + } + fun bar(x: Exception = `_`) {} + class Bar(`_`: Exception = `_`) { + inner class Bar2(x: Exception = `_`) { } + } + } + } catch (_: Exception) { + `_`.stackTrace + val y1 = _ + val y2 = (`_`) + } + try { + TODO() + } catch (_: Exception) { + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo1 = { `_`: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } + val boo2 = { _: Exception -> + try { + TODO() + } catch (x: Exception) { + `_`.stackTrace + } + } +} diff --git a/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.txt b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.txt new file mode 100644 index 00000000000..65a6ac47e1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.txt @@ -0,0 +1,3 @@ +package + +public fun foo(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 80f7ff82137..d68ceea647c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19209,6 +19209,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.kt"); } + @TestMetadata("underscoreInCatchBlock.kt") + public void testUnderscoreInCatchBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt"); + } + + @TestMetadata("underscoreInCatchBlockWithEnabledFeature.kt") + public void testUnderscoreInCatchBlockWithEnabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt"); + } + @TestMetadata("wrongNumberOfTypeArguments.kt") public void testWrongNumberOfTypeArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 5f7840a1c53..43b6b935b0c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -19199,6 +19199,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/resolve/typeParameterInDefaultValueInLocalFunction.kt"); } + @TestMetadata("underscoreInCatchBlock.kt") + public void testUnderscoreInCatchBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlock.kt"); + } + + @TestMetadata("underscoreInCatchBlockWithEnabledFeature.kt") + public void testUnderscoreInCatchBlockWithEnabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/underscoreInCatchBlockWithEnabledFeature.kt"); + } + @TestMetadata("wrongNumberOfTypeArguments.kt") public void testWrongNumberOfTypeArguments() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/wrongNumberOfTypeArguments.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 37e5530f6af..eb78fea16c5 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -138,6 +138,7 @@ enum class LanguageFeature( InferenceCompatibility(KOTLIN_1_5, kind = BUG_FIX), RequiredPrimaryConstructorDelegationCallInEnums(KOTLIN_1_5, kind = BUG_FIX), ForbidAnonymousReturnTypesInPrivateInlineFunctions(KOTLIN_1_5, kind = BUG_FIX), + ForbidReferencingToUnderscoreNamedParameterOfCatchBlock(KOTLIN_1_5, kind = BUG_FIX), // Temporarily disabled, see KT-27084/KT-22379 SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX), diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt index 4d1a7277158..8fd4f4eca96 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt @@ -452,3 +452,6 @@ fun ModuleDescriptor.getKotlinTypeRefiner(): KotlinTypeRefiner = getCapability(R @OptIn(TypeRefinement::class) fun ModuleDescriptor.isTypeRefinementEnabled(): Boolean = getCapability(REFINER_CAPABILITY)?.value != null + +val VariableDescriptor.isUnderscoreNamed + get() = name.identifier == "_"