[FE] Support resolve of until operator to rangeUntil

^KT-52420 Fixed
This commit is contained in:
Victor Petukhov
2022-05-23 14:54:56 +02:00
committed by teamcity
parent 19136019e4
commit 0b25ce4de9
14 changed files with 136 additions and 0 deletions
@@ -22343,6 +22343,28 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
public void testPlusAssignOnVarAndCollections() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnVarAndCollections.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/until")
@TestDataPath("$PROJECT_ROOT")
public class Until {
@Test
public void testAllFilesPresentInUntil() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/operatorsOverloading/until"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("custom.kt")
public void testCustom() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt");
}
}
}
@Nested
@@ -22343,6 +22343,28 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
public void testPlusAssignOnVarAndCollections() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnVarAndCollections.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/until")
@TestDataPath("$PROJECT_ROOT")
public class Until {
@Test
public void testAllFilesPresentInUntil() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/operatorsOverloading/until"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("custom.kt")
public void testCustom() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt");
}
}
}
@Nested
@@ -22343,6 +22343,28 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
public void testPlusAssignOnVarAndCollections() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnVarAndCollections.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/until")
@TestDataPath("$PROJECT_ROOT")
public class Until {
@Test
public void testAllFilesPresentInUntil() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/operatorsOverloading/until"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("custom.kt")
public void testCustom() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt");
}
}
}
@Nested
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.ITERATOR
import org.jetbrains.kotlin.util.OperatorNameConventions.NEXT
import org.jetbrains.kotlin.util.OperatorNameConventions.PROVIDE_DELEGATE
import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_TO
import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_UNTIL
import org.jetbrains.kotlin.util.OperatorNameConventions.SET
import org.jetbrains.kotlin.util.OperatorNameConventions.SET_VALUE
import org.jetbrains.kotlin.util.OperatorNameConventions.SIMPLE_UNARY_OPERATION_NAMES
@@ -179,6 +180,7 @@ private object OperatorFunctionChecks {
checkFor(NEXT, memberOrExtension, ValueParametersCount.none)
checkFor(HAS_NEXT, memberOrExtension, ValueParametersCount.none, Returns.boolean)
checkFor(RANGE_TO, memberOrExtension, ValueParametersCount.single, noDefaultAndVarargs)
checkFor(RANGE_UNTIL, memberOrExtension, ValueParametersCount.single, noDefaultAndVarargs)
checkFor(
EQUALS,
member,
@@ -62,6 +62,7 @@ public class OperatorConventions {
.put(KtTokens.DIV, DIV)
.put(KtTokens.PERC, REM)
.put(KtTokens.RANGE, RANGE_TO)
.put(KtTokens.RANGE_UNTIL, RANGE_UNTIL)
.build();
public static final ImmutableBiMap<Name, Name> REM_TO_MOD_OPERATION_NAMES = ImmutableBiMap.<Name, Name>builder()
@@ -0,0 +1,9 @@
class A {
operator fun rangeUntil(other: A): Iterable<A> = TODO()
}
fun main(n: A, f: A) {
for (i in f..<n) {
}
}
@@ -0,0 +1,9 @@
class A {
operator fun rangeUntil(other: A): Iterable<A> = TODO()
}
fun main(n: A, f: A) {
for (i in f..<n) {
}
}
@@ -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<A>
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,5 @@
fun main(n: Int) {
for (i in <!ITERATOR_MISSING!>0<!UNRESOLVED_REFERENCE!>..<<!>n<!>) {
}
}
@@ -0,0 +1,5 @@
fun main(n: Int) {
for (i in 0<!UNRESOLVED_REFERENCE!>..<<!>n) {
}
}
@@ -0,0 +1,3 @@
package
public fun main(/*0*/ n: kotlin.Int): kotlin.Unit
@@ -22349,6 +22349,28 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
public void testPlusAssignOnVarAndCollections() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/plusAssignOnVarAndCollections.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/until")
@TestDataPath("$PROJECT_ROOT")
public class Until {
@Test
public void testAllFilesPresentInUntil() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/operatorsOverloading/until"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("custom.kt")
public void testCustom() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/custom.kt");
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/until/simple.kt");
}
}
}
@Nested
@@ -61,6 +61,7 @@ object OperatorNameConventions {
@JvmField val MOD = Name.identifier("mod")
@JvmField val REM = Name.identifier("rem")
@JvmField val RANGE_TO = Name.identifier("rangeTo")
@JvmField val RANGE_UNTIL = Name.identifier("rangeUntil")
@JvmField val TIMES_ASSIGN = Name.identifier("timesAssign")
@JvmField val DIV_ASSIGN = Name.identifier("divAssign")
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.ITERATOR
import org.jetbrains.kotlin.util.OperatorNameConventions.NEXT
import org.jetbrains.kotlin.util.OperatorNameConventions.PROVIDE_DELEGATE
import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_TO
import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_UNTIL
import org.jetbrains.kotlin.util.OperatorNameConventions.SET
import org.jetbrains.kotlin.util.OperatorNameConventions.SET_VALUE
import org.jetbrains.kotlin.util.OperatorNameConventions.SIMPLE_UNARY_OPERATION_NAMES
@@ -194,6 +195,7 @@ object OperatorChecks : AbstractModifierChecks() {
Checks(NEXT, MemberOrExtension, NoValueParameters),
Checks(HAS_NEXT, MemberOrExtension, NoValueParameters, ReturnsBoolean),
Checks(RANGE_TO, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
Checks(RANGE_UNTIL, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
Checks(EQUALS, Member) {
fun DeclarationDescriptor.isAny() = this is ClassDescriptor && KotlinBuiltIns.isAny(this)
ensure(containingDeclaration.isAny() || overriddenDescriptors.any { it.containingDeclaration.isAny() }) {