From f5f398788de7508dd2033cb277b010a3acd52792 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 30 May 2022 14:30:21 +0200 Subject: [PATCH] [FE 1.0] Add checker to report "unsupported range until operator" on declaration itself --- .../resolve/PlatformConfiguratorBase.kt | 1 + ...UnsupportedUntilRangeDeclarationChecker.kt | 29 +++++++++++++++++++ .../until/customDefault.kt | 2 +- .../until/customDisabled.kt | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilRangeDeclarationChecker.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index b1b7148c71f..bdd2bec9dca 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -52,6 +52,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf( ValueParameterUsageInDefaultArgumentChecker, CyclicAnnotationsChecker, ExpressionAfterTypeParameterWithoutSpacingChecker, + UnsupportedUntilRangeDeclarationChecker, ) private val DEFAULT_CALL_CHECKERS = listOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilRangeDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilRangeDeclarationChecker.kt new file mode 100644 index 00000000000..26cdfde70a5 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/UnsupportedUntilRangeDeclarationChecker.kt @@ -0,0 +1,29 @@ +/* + * 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 org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker +import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext +import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_UNTIL + +object UnsupportedUntilRangeDeclarationChecker : DeclarationChecker { + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { + val isRangeUntilOperatorSupported = context.languageVersionSettings.supportsFeature(LanguageFeature.RangeUntilOperator) + + if (!isRangeUntilOperatorSupported && descriptor is FunctionDescriptor && descriptor.isOperator && descriptor.name == RANGE_UNTIL) { + val operatorKeyword = declaration.modifierList?.getModifier(KtTokens.OPERATOR_KEYWORD) ?: return + context.trace.report( + Errors.UNSUPPORTED_FEATURE.on(operatorKeyword, LanguageFeature.RangeUntilOperator to context.languageVersionSettings) + ) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt index 4194ef77515..c01b535f11a 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDefault.kt @@ -1,5 +1,5 @@ class A { - operator fun rangeUntil(other: A): Iterable = TODO() + operator fun rangeUntil(other: A): Iterable = TODO() } fun main(n: A, f: A) { diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt index 24d88f8bd12..d51916961de 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/until/customDisabled.kt @@ -1,7 +1,7 @@ // !LANGUAGE: -RangeUntilOperator class A { - operator fun rangeUntil(other: A): Iterable = TODO() + operator fun rangeUntil(other: A): Iterable = TODO() } fun main(n: A, f: A) {