From c2663031975d7468bb4dd7fe8a63956d875c0b66 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 24 May 2022 11:45:04 +0200 Subject: [PATCH] [FE 1.0] Introduce "range until operator" language feature, and report errors on its usages till 1.8 --- ...CompilerTestFE10TestdataTestGenerated.java | 12 +++++++++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 +++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 +++++++++ .../resolve/PlatformConfiguratorBase.kt | 3 +-- .../UnsupportedUntilOperatorChecker.kt | 26 +++++++++++++++++++ .../operatorsOverloading/until/custom.kt | 3 +++ .../{custom.fir.kt => customDefault.fir.kt} | 0 .../until/customDefault.kt | 9 +++++++ .../until/customDefault.txt | 11 ++++++++ .../until/customDisabled.fir.kt | 11 ++++++++ .../until/customDisabled.kt | 11 ++++++++ .../until/customDisabled.txt | 11 ++++++++ .../operatorsOverloading/until/simple.fir.kt | 2 ++ .../operatorsOverloading/until/simple.kt | 2 ++ .../test/runners/DiagnosticTestGenerated.java | 12 +++++++++ .../kotlin/config/LanguageVersionSettings.kt | 1 + 16 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilOperatorChecker.kt rename compiler/testData/diagnostics/tests/operatorsOverloading/until/{custom.fir.kt => customDefault.fir.kt} (100%) create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.txt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt create mode 100644 compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 4a5d848aa88..012838bf62a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -22359,6 +22359,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt"); } + @Test + @TestMetadata("customDefault.kt") + public void testCustomDefault() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt"); + } + + @Test + @TestMetadata("customDisabled.kt") + public void testCustomDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index afe1fb2299f..7d742f23647 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -22359,6 +22359,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt"); } + @Test + @TestMetadata("customDefault.kt") + public void testCustomDefault() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt"); + } + + @Test + @TestMetadata("customDisabled.kt") + public void testCustomDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index b93ff412c57..4578948dc2f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -22359,6 +22359,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt"); } + @Test + @TestMetadata("customDefault.kt") + public void testCustomDefault() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt"); + } + + @Test + @TestMetadata("customDisabled.kt") + public void testCustomDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index 1413cd89a09..b1b7148c71f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -68,8 +68,7 @@ private val DEFAULT_CALL_CHECKERS = listOf( UnitConversionCallChecker, FunInterfaceConstructorReferenceChecker, NullableExtensionOperatorWithSafeCallChecker, ReferencingToUnderscoreNamedParameterOfCatchBlockChecker, VarargWrongExecutionOrderChecker, SelfCallInNestedObjectConstructorChecker, NewSchemeOfIntegerOperatorResolutionChecker, EnumEntryVsCompanionPriorityCallChecker, CompanionInParenthesesLHSCallChecker, - ResolutionToPrivateConstructorOfSealedClassChecker, - EqualityCallChecker, + ResolutionToPrivateConstructorOfSealedClassChecker, EqualityCallChecker, UnsupportedUntilOperatorChecker ) 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/UnsupportedUntilOperatorChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilOperatorChecker.kt new file mode 100644 index 00000000000..8e2b7b86329 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilOperatorChecker.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2022 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.config.LanguageFeature +import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED_FEATURE +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtOperationReferenceExpression +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall + +object UnsupportedUntilOperatorChecker : CallChecker { + override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { + val calleeExpression = resolvedCall.call.calleeExpression as? KtOperationReferenceExpression ?: return + val isRangeUntilOperatorSupported = context.languageVersionSettings.supportsFeature(LanguageFeature.RangeUntilOperator) + + if (calleeExpression.operationSignTokenType == KtTokens.RANGE_UNTIL && !isRangeUntilOperatorSupported) { + context.trace.report( + UNSUPPORTED_FEATURE.on(reportOn, LanguageFeature.RangeUntilOperator to context.languageVersionSettings) + ) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt index 246bbf649b8..8e5e3fdea38 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt @@ -1,3 +1,6 @@ +// FIR_IDENTICAL +// !LANGUAGE: +RangeUntilOperator + class A { operator fun rangeUntil(other: A): Iterable = TODO() } diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.fir.kt similarity index 100% rename from compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.fir.kt rename to compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.fir.kt diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt new file mode 100644 index 00000000000..4194ef77515 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt @@ -0,0 +1,9 @@ +class A { + operator fun rangeUntil(other: A): Iterable = TODO() +} + +fun main(n: A, f: A) { + for (i in f..<n) { + + } +} diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.txt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.txt new file mode 100644 index 00000000000..eec632d4253 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.txt @@ -0,0 +1,11 @@ +package + +public fun main(/*0*/ n: A, /*1*/ f: A): kotlin.Unit + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun rangeUntil(/*0*/ other: A): kotlin.collections.Iterable + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.fir.kt new file mode 100644 index 00000000000..580b1f49a5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: -RangeUntilOperator + +class A { + operator fun rangeUntil(other: A): Iterable = TODO() +} + +fun main(n: A, f: A) { + for (i in f.. = TODO() +} + +fun main(n: A, f: A) { + for (i in f..<n) { + + } +} diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.txt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.txt new file mode 100644 index 00000000000..eec632d4253 --- /dev/null +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.txt @@ -0,0 +1,11 @@ +package + +public fun main(/*0*/ n: A, /*1*/ f: A): kotlin.Unit + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun rangeUntil(/*0*/ other: A): kotlin.collections.Iterable + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.fir.kt index 21f9589e026..0ee75ae9300 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.fir.kt @@ -1,3 +1,5 @@ +// !LANGUAGE: +RangeUntilOperator + fun main(n: Int) { for (i in 0..<n) { diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt index 81e5f65dd37..4ec6e701a2d 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt @@ -1,3 +1,5 @@ +// !LANGUAGE: +RangeUntilOperator + fun main(n: Int) { for (i in 0..<n) { 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 e006ee01b3a..3284e1f69d5 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 @@ -22365,6 +22365,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt"); } + @Test + @TestMetadata("customDefault.kt") + public void testCustomDefault() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt"); + } + + @Test + @TestMetadata("customDisabled.kt") + public void testCustomDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 77357c8d3fd..2578df1f24c 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -262,6 +262,7 @@ enum class LanguageFeature( ReportNonVarargSpreadOnGenericCalls(KOTLIN_1_8, kind = BUG_FIX), // KT-48162 AllowExpressionAfterTypeReferenceWithoutSpacing(KOTLIN_1_8, kind = BUG_FIX), // KT-35811 RefineTypeCheckingOnAssignmentsToJavaFields(KOTLIN_1_8, kind = BUG_FIX), + RangeUntilOperator(KOTLIN_1_8), // KT-15613 // 1.9