From 64db96eda35b20102ffffd34e4b5ebb07fae93d6 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Tue, 7 Nov 2023 17:06:55 +0100 Subject: [PATCH] [K1, K2] Use safe names when accessing to type parameters ^KT-57529 Fixed --- .../DiagnosticCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...versedDiagnosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ .../FirLightTreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../FirPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../kotlin/fir/resolve/inference/ConeTypeVariables.kt | 3 ++- .../kotlin/resolve/calls/inference/model/TypeVariable.kt | 4 ++-- .../tests/exceptions/keywordsInsteadOfIdentifiers.kt | 8 ++++++++ .../kotlin/test/runners/DiagnosticTestGenerated.java | 6 ++++++ 8 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 1c1cd76669b..0732c18a821 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -12306,6 +12306,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/exceptions/incorrectCallOnILT.kt"); } + @Test + @TestMetadata("keywordsInsteadOfIdentifiers.kt") + public void testKeywordsInsteadOfIdentifiers() throws Exception { + runTest("compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt"); + } + @Test @TestMetadata("kt24158.kt") public void testKt24158() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 1e6ccf602a8..79b94052f48 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -12306,6 +12306,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/exceptions/incorrectCallOnILT.kt"); } + @Test + @TestMetadata("keywordsInsteadOfIdentifiers.kt") + public void testKeywordsInsteadOfIdentifiers() throws Exception { + runTest("compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt"); + } + @Test @TestMetadata("kt24158.kt") public void testKt24158() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 755686c3561..61ead43d606 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -12300,6 +12300,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/exceptions/incorrectCallOnILT.kt"); } + @Test + @TestMetadata("keywordsInsteadOfIdentifiers.kt") + public void testKeywordsInsteadOfIdentifiers() throws Exception { + runTest("compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt"); + } + @Test @TestMetadata("kt24158.kt") public void testKt24158() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 754e7c8375e..623881c1255 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -12306,6 +12306,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/exceptions/incorrectCallOnILT.kt"); } + @Test + @TestMetadata("keywordsInsteadOfIdentifiers.kt") + public void testKeywordsInsteadOfIdentifiers() throws Exception { + runTest("compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt"); + } + @Test @TestMetadata("kt24158.kt") public void testKt24158() throws Exception { diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt index 80cf58f27df..34fcf130317 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/inference/ConeTypeVariables.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.inference import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.ConeTypeVariable +import org.jetbrains.kotlin.name.SpecialNames class ConeTypeVariableForPostponedAtom(name: String) : ConeTypeVariable(name) class ConeTypeVariableForLambdaParameterType(name: String, val index: Int) : ConeTypeVariable(name) @@ -15,4 +16,4 @@ class ConeTypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, na class ConeTypeParameterBasedTypeVariable( val typeParameterSymbol: FirTypeParameterSymbol -) : ConeTypeVariable(typeParameterSymbol.name.identifier, typeParameterSymbol.toLookupTag()) +) : ConeTypeVariable(SpecialNames.safeIdentifier(typeParameterSymbol.name).identifier, typeParameterSymbol.toLookupTag()) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt index ee878131512..84f41f57c8b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.model import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.resolve.calls.model.PostponableKotlinCallArgument import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.hasOnlyInputTypesAnnotation @@ -76,7 +76,7 @@ fun TypeConstructor.typeForTypeVariable(): SimpleType { class TypeVariableFromCallableDescriptor( val originalTypeParameter: TypeParameterDescriptor -) : NewTypeVariable(originalTypeParameter.builtIns, originalTypeParameter.name.identifier, originalTypeParameter) { +) : NewTypeVariable(originalTypeParameter.builtIns, SpecialNames.safeIdentifier(originalTypeParameter.name).identifier, originalTypeParameter) { override fun hasOnlyInputTypesAnnotation(): Boolean = originalTypeParameter.hasOnlyInputTypesAnnotation() } diff --git a/compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt b/compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt new file mode 100644 index 00000000000..8da50c43bfa --- /dev/null +++ b/compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt @@ -0,0 +1,8 @@ +// FIR_IDENTICAL +// ISSUE: KT-57529 + +fun <break> foo() {} + +fun test(){ + foo() +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 429fb336cde..3fb0af87203 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -12306,6 +12306,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/exceptions/incorrectCallOnILT.kt"); } + @Test + @TestMetadata("keywordsInsteadOfIdentifiers.kt") + public void testKeywordsInsteadOfIdentifiers() throws Exception { + runTest("compiler/testData/diagnostics/tests/exceptions/keywordsInsteadOfIdentifiers.kt"); + } + @Test @TestMetadata("kt24158.kt") public void testKt24158() throws Exception {