From 2dd8727baf0927faa60db38427005eb7171780ba Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Wed, 18 Dec 2019 01:10:07 -0800 Subject: [PATCH] [JVM IR] ForLoopsLowering: Keep IMPLICIT_NOTNULL type-casts in `next()` and `componentN()` calls. There were issues when we have iterables from Java where the element type has "not null" type information. --- .../common/lower/loops/ForLoopsLowering.kt | 89 ++++++++- .../common/lower/loops/HeaderProcessor.kt | 38 +++- .../ir/util/DeepCopyIrTreeWithSymbols.kt | 11 +- .../javaArrayOfInheritedNotNull.kt | 30 +++ .../javaArrayOfInheritedNotNullFailFast.kt | 42 ++++ .../javaInterop/javaArrayOfMaybeNullable.kt | 23 +++ ...yOfMaybeNullableWithNotNullLoopVariable.kt | 23 +++ ...NullableWithNotNullLoopVariableFailFast.kt | 36 ++++ .../javaCollectionOfExplicitNotNull.kt | 42 ++++ ...javaCollectionOfExplicitNotNullFailFast.kt | 51 +++++ .../javaCollectionOfExplicitNullable.kt | 42 ++++ .../javaCollectionOfInheritedNotNull.kt | 34 ++++ ...avaCollectionOfInheritedNotNullFailFast.kt | 43 ++++ .../javaCollectionOfMaybeNullable.kt | 28 +++ ...nOfMaybeNullableWithNotNullLoopVariable.kt | 28 +++ ...NullableWithNotNullLoopVariableFailFast.kt | 38 ++++ .../javaCollectionOfNotNullFromStdlib.kt | 22 +++ ...llectionOfNotNullFromStdlibToTypedArray.kt | 23 +++ .../javaCollectionOfNotNullToTypedArray.kt | 42 ++++ ...CollectionOfNotNullToTypedArrayFailFast.kt | 51 +++++ .../javaInterop/javaIteratorOfNotNull.kt | 42 ++++ .../javaIteratorOfNotNullFailFast.kt | 51 +++++ .../javaArrayOfInheritedNotNullWithIndex.kt | 33 ++++ ...rrayOfInheritedNotNullWithIndexFailFast.kt | 43 ++++ .../javaArrayOfMaybeNullableWithIndex.kt | 26 +++ ...ullableWithIndexWithNotNullLoopVariable.kt | 26 +++ ...ithIndexWithNotNullLoopVariableFailFast.kt | 33 ++++ ...avaCollectionOfExplicitNotNullWithIndex.kt | 45 +++++ ...ctionOfExplicitNotNullWithIndexFailFast.kt | 52 +++++ ...vaCollectionOfExplicitNullableWithIndex.kt | 45 +++++ .../javaCollectionOfMaybeNullableWithIndex.kt | 31 +++ ...ullableWithIndexWithNotNullLoopVariable.kt | 31 +++ ...ithIndexWithNotNullLoopVariableFailFast.kt | 35 ++++ .../javaIteratorOfNotNullWithIndex.kt | 45 +++++ .../javaIteratorOfNotNullWithIndexFailFast.kt | 52 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 186 ++++++++++++++++++ .../LightAnalysisModeTestGenerated.java | 186 ++++++++++++++++++ .../ir/FirBlackBoxCodegenTestGenerated.java | 186 ++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 186 ++++++++++++++++++ .../IrJsCodegenBoxTestGenerated.java | 26 +++ .../semantics/JsCodegenBoxTestGenerated.java | 26 +++ 41 files changed, 2102 insertions(+), 20 deletions(-) create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt create mode 100644 compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt index 65d9b893bf6..e263a261676 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase +import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrFile @@ -17,8 +18,8 @@ import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl import org.jetbrains.kotlin.ir.util.dump -import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid -import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid +import org.jetbrains.kotlin.ir.util.render +import org.jetbrains.kotlin.ir.visitors.* val forLoopsPhase = makeIrFilePhase( ::ForLoopsLowering, @@ -230,7 +231,7 @@ private class RangeLoopTransformer( // // val i = inductionVariable // For progressions, or `array[inductionVariable]` for arrays // inductionVariable = inductionVariable + step - val initializer = mainLoopVariable.initializer as IrCall + val initializer = mainLoopVariable.initializer!! val replacement = with(context.createIrBuilder(getScopeOwnerSymbol(), initializer.startOffset, initializer.endOffset)) { IrCompositeImpl( mainLoopVariable.startOffset, @@ -269,6 +270,35 @@ private class RangeLoopTransformer( val loopVariableComponentIndices: List ) + private class FindInitializerCallVisitor(private val mainLoopVariable: IrVariable?) : IrElementVisitorVoid { + var initializerCall: IrCall? = null + + override fun visitElement(element: IrElement) { + element.acceptChildrenVoid(this) + } + + override fun visitCall(expression: IrCall) { + val candidateCall = when (expression.origin) { + IrStatementOrigin.FOR_LOOP_NEXT -> expression + is IrStatementOrigin.COMPONENT_N -> + if (mainLoopVariable != null && (expression.dispatchReceiver as? IrGetValue)?.symbol == mainLoopVariable.symbol) { + expression + } else { + null + } + else -> null + } + + when { + candidateCall == null -> super.visitCall(expression) + initializerCall == null -> initializerCall = candidateCall + else -> throw IllegalStateException( + "Multiple initializer calls found. First: ${initializerCall!!.render()}\nSecond: ${candidateCall.render()}" + ) + } + } + } + private fun gatherLoopVariableInfo(statements: MutableList): LoopVariableInfo { // The "next" statement (at the top of the loop) looks something like: // @@ -288,19 +318,58 @@ private class RangeLoopTransformer( val loopVariableComponentIndices = mutableListOf() for ((i, stmt) in statements.withIndex()) { if (stmt !is IrVariable) continue - val initializer = stmt.initializer as? IrCall + val initializer = stmt.initializer?.let { + // The `next()` and `componentN()` calls could be wrapped in an IMPLICIT_NOTNULL type-cast when the iterator comes from Java + // and the iterator's type parameter has enhanced nullability information (either explicit or implicit). Therefore we need + // to traverse the initializer to find the `next()` or `componentN()` call. Example: + // + // // In Java: + // public static Collection<@NotNull String> collection() { /* ... */ } + // + // // In Kotlin: + // for ((i, s) in JavaClass.collection().withIndex()) { + // println("$i: ${s.toUpperCase()}") // NOTE: `s` is not nullable + // } + // + // The variable declaration for `s` looks like this: + // + // VAR name:s type:@[NotNull(...)] kotlin.String [val] + // TYPE_OP type=@[NotNull(...)] kotlin.String origin=IMPLICIT_NOTNULL typeOperand=@[NotNull(...)] kotlin.String + // CALL 'public final fun component2 (): T of ...IndexedValue [operator] declared in ...IndexedValue' type=@[NotNull(...)] kotlin.String origin=COMPONENT_N(index=2) + // $this: GET_VAR 'val tmp1_loop_parameter: ...IndexedValue<@[NotNull(...)] kotlin.String> [val] declared in .box' type=...IndexedValue<@[NotNull(...)] kotlin.String> origin=null + // + // Enhanced nullability information can be implicit if the Java function overrides a Kotlin function. Example: + // + // // In Java: + // public class AImpl implements A { + // // NOTE: The array and String are both implicitly not nullable because they are not nullable in A.array() + // @Override public String[] array() { return new String[0]; } + // } + // + // // In Kotlin + // interface A { + // fun array(): Array + // } + // for (s in AImpl().array()) { + // println(s.toUpperCase()) // NOTE: `s` is not nullable + // } + // + // The variable declaration for `s` looks like this: + // + // VAR name:s type:kotlin.String [val] + // TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + // CALL 'public abstract fun next (): T of ...Iterator [operator] declared in ...Iterator' type=kotlin.String origin=FOR_LOOP_NEXT + // $this: GET_VAR 'val tmp0_iterator: ...Iterator [val] declared in .box' type=...Iterator origin=null + FindInitializerCallVisitor(mainLoopVariable).apply { it.acceptVoid(this) }.initializerCall + } when (val origin = initializer?.origin) { IrStatementOrigin.FOR_LOOP_NEXT -> { mainLoopVariable = stmt mainLoopVariableIndex = i } is IrStatementOrigin.COMPONENT_N -> { - if (mainLoopVariable != null && - (initializer.dispatchReceiver as? IrGetValue)?.symbol == mainLoopVariable.symbol - ) { - loopVariableComponents[origin.index] = stmt - loopVariableComponentIndices.add(i) - } + loopVariableComponents[origin.index] = stmt + loopVariableComponentIndices.add(i) } } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt index 1d22053a8d1..809496e8ef5 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt @@ -22,9 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrDoWhileLoopImpl import org.jetbrains.kotlin.ir.expressions.impl.IrWhileLoopImpl import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.types.* -import org.jetbrains.kotlin.ir.util.coerceToUnitIfNeeded -import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols -import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.util.OperatorNameConventions /** @@ -303,6 +301,22 @@ internal class ProgressionLoopHeader( } } +private class InitializerCallReplacer(symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper, val replacementCall: IrCall) : + DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) { + var initializerCall: IrCall? = null + + override fun visitCall(expression: IrCall): IrCall { + if (initializerCall == null) { + initializerCall = expression + return replacementCall + } else { + throw IllegalStateException( + "Multiple initializer calls found. First: ${initializerCall!!.render()}\nSecond: ${expression.render()}" + ) + } + } +} + internal class IndexedGetLoopHeader( headerInfo: IndexedGetHeaderInfo, builder: DeclarationIrBuilder @@ -319,11 +333,15 @@ internal class IndexedGetLoopHeader( with(builder) { // loopVariable = objectVariable[inductionVariable] val indexedGetFun = with(headerInfo.expressionHandler) { headerInfo.objectVariable.type.getFunction } - val get = irCall(indexedGetFun).apply { + val get = irCall(indexedGetFun.symbol).apply { dispatchReceiver = irGet(headerInfo.objectVariable) putValueArgument(0, irGet(inductionVariable)) } - loopVariable?.initializer = get + // The call could be wrapped in an IMPLICIT_NOTNULL type-cast (see comment in ForLoopsLowering.gatherLoopVariableInfo()). + // Find and replace the call to preserve any type-casts. + loopVariable?.initializer = loopVariable?.initializer?.deepCopyWithSymbols { symbolRemapper, typeRemapper -> + InitializerCallReplacer(symbolRemapper, typeRemapper, get) + } // Even if there is no loop variable, we always want to call `get()` as it may have side-effects. // The un-lowered loop always calls `get()` on each iteration. listOf(loopVariable ?: get) + incrementInductionVariable(this) @@ -517,10 +535,16 @@ internal class IterableLoopHeader( // loopVariable = iteratorVar.next() val iteratorClass = headerInfo.iteratorVariable.type.getClass()!! val next = - irCall(iteratorClass.functions.first { it.name == OperatorNameConventions.NEXT && it.valueParameters.isEmpty() }).apply { + irCall(iteratorClass.functions.first { + it.name == OperatorNameConventions.NEXT && it.valueParameters.isEmpty() + }.symbol).apply { dispatchReceiver = irGet(headerInfo.iteratorVariable) } - loopVariable?.initializer = next + // The call could be wrapped in an IMPLICIT_NOTNULL type-cast (see comment in ForLoopsLowering.gatherLoopVariableInfo()). + // Find and replace the call to preserve any type-casts. + loopVariable?.initializer = loopVariable?.initializer?.deepCopyWithSymbols { symbolRemapper, typeRemapper -> + InitializerCallReplacer(symbolRemapper, typeRemapper, next) + } // Even if there is no loop variable, we always want to call `next()` for iterables and sequences. listOf(loopVariable ?: next.coerceToUnitIfNeeded(next.type, context.irBuiltIns)) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt index 1dc7c5fd1ec..1430cdbe878 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt @@ -33,11 +33,14 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import java.util.* -inline fun T.deepCopyWithSymbols(initialParent: IrDeclarationParent? = null): T { +inline fun T.deepCopyWithSymbols( + initialParent: IrDeclarationParent? = null, + createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols = ::DeepCopyIrTreeWithSymbols +): T { val symbolRemapper = DeepCopySymbolRemapper() acceptVoid(symbolRemapper) val typeRemapper = DeepCopyTypeRemapper(symbolRemapper) - return transform(DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T + return transform(createCopier(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T } interface SymbolRenamer { @@ -58,9 +61,11 @@ interface SymbolRenamer { open class DeepCopyIrTreeWithSymbols( private val symbolRemapper: SymbolRemapper, private val typeRemapper: TypeRemapper, - private val symbolRenamer: SymbolRenamer = SymbolRenamer.DEFAULT + private val symbolRenamer: SymbolRenamer ) : IrElementTransformerVoid() { + constructor(symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper) : this(symbolRemapper, typeRemapper, SymbolRenamer.DEFAULT) + init { // TODO refactor (typeRemapper as? DeepCopyTypeRemapper)?.let { diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt new file mode 100644 index 00000000000..1f34a1b37af --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in JImpl().arrayOfNotNull()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +interface J { + fun arrayOfNotNull(): Array +} + +// FILE: JImpl.java +public class JImpl implements J { + // The only way to get @EnhancedNullability on the array element type (Int) is to override a Kotlin function that + // returns `Array` (where Int is not nullable). `@NotNull Integer[]` makes the array not nullable, not String. + @Override + public Integer[] arrayOfNotNull() { + return new Integer[] { 42, -42 }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt new file mode 100644 index 00000000000..573ad5db8d6 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get() in loop header". The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i = JImpl().arrayOfNotNull()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i in JImpl().arrayOfNotNull()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +interface J { + fun arrayOfNotNull(): Array +} + +// FILE: JImpl.java +public class JImpl implements J { + // The only way to get @EnhancedNullability on the array element type (Int) is to override a Kotlin function that + // returns `Array` (where Int is not nullable). `@NotNull Integer[]` makes the array not nullable, not String. + @Override + public Integer[] arrayOfNotNull() { + return new Integer[] { null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt new file mode 100644 index 00000000000..229e393d61c --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.arrayOfMaybeNullable()) { + actualValues += i + } + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { 42, null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt new file mode 100644 index 00000000000..7ead8be35ee --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i: Int in J.arrayOfMaybeNullable()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { 42, -42 }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt new file mode 100644 index 00000000000..ed546b0e58d --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with a NullPointerException in the loop header. The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. +// The NPE is due to calling `intValue()` on the null Int; it is expected to be asserted as non-null first. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i: Int = J.arrayOfMaybeNullable()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i: Int in J.arrayOfMaybeNullable()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt new file mode 100644 index 00000000000..4a84576c64a --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.listOfNotNull()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt new file mode 100644 index 00000000000..13d6e45fcac --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt @@ -0,0 +1,51 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get() in loop header". The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i = J.listOfNotNull()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i in J.listOfNotNull()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + return Collections.singletonList(null); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt new file mode 100644 index 00000000000..20436ad39ba --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.listOfNullable()) { + actualValues += i + } + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@Nullable Integer> listOfNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(null); + return list; + } +} + +// FILE: Nullable.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @Nullable does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.Nullable for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface Nullable { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt new file mode 100644 index 00000000000..1e47f47a98f --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in JImpl().listOfNotNull()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +interface J { + fun listOfNotNull(): List +} + +// FILE: JImpl.java +import java.util.*; + +public class JImpl implements J { + // Type argument (Int) gets @EnhancedNullability because it is not nullable in overridden Kotlin function. + @Override + public List listOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt new file mode 100644 index 00000000000..d7d28bbc41b --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get() in loop header". The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i = JImpl().listOfNotNull()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i in JImpl().listOfNotNull()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +interface J { + fun listOfNotNull(): List +} + +// FILE: JImpl.java +import java.util.*; + +public class JImpl implements J { + // Type argument (Int) gets @EnhancedNullability because it is not nullable in overridden Kotlin function. + @Override + public List listOfNotNull() { + return Collections.singletonList(null); + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt new file mode 100644 index 00000000000..38509405997 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.listOfMaybeNullable()) { + actualValues += i + } + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(null); + return list; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt new file mode 100644 index 00000000000..efb9e015049 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i: Int in J.listOfMaybeNullable()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt new file mode 100644 index 00000000000..f7a6e9d0863 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with a NullPointerException in the loop header. The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. +// The NPE is due to calling `intValue()` on the null Int; it is expected to be asserted as non-null first. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i: Int = J.listOfMaybeNullable()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i: Int in J.listOfMaybeNullable()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + return Collections.singletonList(null); + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt new file mode 100644 index 00000000000..0c7229f0482 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +import kotlin.test.* + +fun box(): String { + val map = java.util.LinkedHashMap() + map.put(3, 42) + map.put(14, -42) + + // Even though the type parameters on `map` are not nullable, the `values` property is implemented in Java and therefore there is + // @EnhancedNullability on its type argument (Int). + val actualValues = mutableListOf() + for (v in map.values) { + actualValues += v + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt new file mode 100644 index 00000000000..5dc32e4c5a3 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +import kotlin.test.* + +fun box(): String { + val map = java.util.LinkedHashMap() + map.put(3, 42) + map.put(14, -42) + + // Even though the type parameters on `map` are not nullable, the `values` property is implemented in Java and therefore there is + // @EnhancedNullability on its type argument (Int), which gets propagated on the call to `toTypedArray()`. + // If we simply called `map.toTypedArray()` there would be no @EnhancedNullability on Int. + val actualValues = mutableListOf() + for (v in map.values.toTypedArray()) { + actualValues += v + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt new file mode 100644 index 00000000000..dc05053a6c6 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.listOfNotNull().toTypedArray()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt new file mode 100644 index 00000000000..4ab724ccb20 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt @@ -0,0 +1,51 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get() in loop header". The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i = J.listOfNotNull().toTypedArray()[0] + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i in J.listOfNotNull().toTypedArray()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + return Collections.singletonList(null); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt new file mode 100644 index 00000000000..a50e023af01 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualValues = mutableListOf() + for (i in J.iteratorOfNotNull()) { + actualValues += i + } + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static Iterator<@NotNull Integer> iteratorOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list.iterator(); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt new file mode 100644 index 00000000000..08bf80668e4 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt @@ -0,0 +1,51 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get() in loop header". The not-null assertion is not generated when +// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val i = J.iteratorOfNotNull().next() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for (i in J.iteratorOfNotNull()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static Iterator<@NotNull Integer> iteratorOfNotNull() { + return Collections.singletonList(null).iterator(); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt new file mode 100644 index 00000000000..dee9ec44677 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in JImpl().arrayOfNotNull().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +interface J { + fun arrayOfNotNull(): Array +} + +// FILE: JImpl.java +public class JImpl implements J { + // The only way to get @EnhancedNullability on the array element type (Int) is to override a Kotlin function that + // returns `Array` (where Int is not nullable). `@NotNull Integer[]` makes the array not nullable, not String. + @Override + public Integer[] arrayOfNotNull() { + return new Integer[] { 42, -42 }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt new file mode 100644 index 00000000000..164ef78eb02 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get()". The not-null assertion is not generated when assigning to the +// variables in the destructuring declaration. The root cause seems to be that +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on +// KtDestructuringDeclarations and their entries. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val (index, i) = JImpl().arrayOfNotNull().withIndex().first() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for ((index, i) in JImpl().arrayOfNotNull().withIndex()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +interface J { + fun arrayOfNotNull(): Array +} + +// FILE: JImpl.java +public class JImpl implements J { + // The only way to get @EnhancedNullability on the array element type (Int) is to override a Kotlin function that + // returns `Array` (where Int is not nullable). `@NotNull Integer[]` makes the array not nullable, not String. + @Override + public Integer[] arrayOfNotNull() { + return new Integer[] { null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt new file mode 100644 index 00000000000..2a044443ef7 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in J.arrayOfMaybeNullable().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { 42, null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt new file mode 100644 index 00000000000..bd9a434fa26 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i: Int) in J.arrayOfMaybeNullable().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { 42, -42 }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt new file mode 100644 index 00000000000..84d3199dae0 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM, JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails because explicit types are ignored in destructuring declarations (KT-22392). + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val (index, i: Int) = J.arrayOfMaybeNullable().withIndex().first() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for ((index, i: Int) in J.arrayOfMaybeNullable().withIndex()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +public class J { + public static Integer[] arrayOfMaybeNullable() { + return new Integer[] { null }; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt new file mode 100644 index 00000000000..d55d2375c15 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in J.listOfNotNull().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt new file mode 100644 index 00000000000..97678400f4b --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt @@ -0,0 +1,52 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get()". The not-null assertion is not generated when assigning to the +// variables in the destructuring declaration. The root cause seems to be that +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on +// KtDestructuringDeclarations and their entries. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val (index, i) = J.listOfNotNull().withIndex().first() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for ((index, i) in J.listOfNotNull().withIndex()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@NotNull Integer> listOfNotNull() { + return Collections.singletonList(null); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt new file mode 100644 index 00000000000..e88b8c44dab --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in J.listOfNullable().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static List<@Nullable Integer> listOfNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(null); + return list; + } +} + +// FILE: Nullable.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @Nullable does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.Nullable for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface Nullable { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt new file mode 100644 index 00000000000..25df14cf2e3 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in J.listOfMaybeNullable().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, null), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(null); + return list; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt new file mode 100644 index 00000000000..68d4ba97c66 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt @@ -0,0 +1,31 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i: Int) in J.listOfMaybeNullable().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list; + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt new file mode 100644 index 00000000000..7fd35640643 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt @@ -0,0 +1,35 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM, JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails because explicit types are ignored in destructuring declarations (KT-22392). + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val (index, i: Int) = J.listOfMaybeNullable().withIndex().first() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for ((index, i: Int) in J.listOfMaybeNullable().withIndex()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; + +public class J { + public static List listOfMaybeNullable() { + return Collections.singletonList(null); + } +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt new file mode 100644 index 00000000000..79174fea072 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + val actualIndices = mutableListOf() + val actualValues = mutableListOf() + for ((index, i) in J.iteratorOfNotNull().withIndex()) { + actualIndices += index + actualValues += i + } + assertEquals(listOf(0, 1), actualIndices) + assertEquals(listOf(42, -42), actualValues) + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static Iterator<@NotNull Integer> iteratorOfNotNull() { + List list = new ArrayList<>(); + list.add(42); + list.add(-42); + return list.iterator(); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt new file mode 100644 index 00000000000..b70982ab3a8 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt @@ -0,0 +1,52 @@ +// !LANGUAGE: +StrictJavaNullabilityAssertions +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME + +// Note: This fails on JVM (non-IR) with "Fail: should throw on get()". The not-null assertion is not generated when assigning to the +// variables in the destructuring declaration. The root cause seems to be that +// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on +// KtDestructuringDeclarations and their entries. + +// FILE: box.kt +import kotlin.test.* + +fun box(): String { + // Sanity check to make sure there IS an exception even when not in a for-loop + try { + val (index, i) = J.iteratorOfNotNull().withIndex().next() + return "Fail: should throw on get()" + } catch (e: IllegalStateException) {} + + try { + for ((index, i) in J.iteratorOfNotNull().withIndex()) { + return "Fail: should throw on get() in loop header" + } + } + catch (e: IllegalStateException) {} + return "OK" +} + +// FILE: J.java +import java.util.*; +import org.jetbrains.annotations.*; + +public class J { + public static Iterator<@NotNull Integer> iteratorOfNotNull() { + return Collections.singletonList(null).iterator(); + } +} + +// FILE: NotNull.java +package org.jetbrains.annotations; + +import java.lang.annotation.*; + +// org.jetbrains.annotations used in the compiler is version 13, whose @NotNull does not support the TYPE_USE target (version 15 does). +// We're using our own @org.jetbrains.annotations.NotNull for testing purposes. +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) +public @interface NotNull { +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 60b59180a89..2bc123f15ca 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -20929,6 +20929,192 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("javaArrayOfInheritedNotNull.kt") + public void testJavaArrayOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullFailFast.kt") + public void testJavaArrayOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullable.kt") + public void testJavaArrayOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNull.kt") + public void testJavaCollectionOfExplicitNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullFailFast.kt") + public void testJavaCollectionOfExplicitNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullable.kt") + public void testJavaCollectionOfExplicitNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNull.kt") + public void testJavaCollectionOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNullFailFast.kt") + public void testJavaCollectionOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullable.kt") + public void testJavaCollectionOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlib.kt") + public void testJavaCollectionOfNotNullFromStdlib() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlibToTypedArray.kt") + public void testJavaCollectionOfNotNullFromStdlibToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArray.kt") + public void testJavaCollectionOfNotNullToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArrayFailFast.kt") + public void testJavaCollectionOfNotNullToTypedArrayFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNull.kt") + public void testJavaIteratorOfNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt"); + } + + @TestMetadata("javaIteratorOfNotNullFailFast.kt") + public void testJavaIteratorOfNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndex.kt") + public void testJavaArrayOfInheritedNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndexFailFast.kt") + public void testJavaArrayOfInheritedNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndex.kt") + public void testJavaArrayOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndex.kt") + public void testJavaCollectionOfExplicitNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndexFailFast.kt") + public void testJavaCollectionOfExplicitNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullableWithIndex.kt") + public void testJavaCollectionOfExplicitNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndex.kt") + public void testJavaCollectionOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndex.kt") + public void testJavaIteratorOfNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndexFailFast.kt") + public void testJavaIteratorOfNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1d162b3c6bc..7da98a0dc8f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -20929,6 +20929,192 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractLightAnalysisModeTest { + @TestMetadata("javaArrayOfInheritedNotNullFailFast.kt") + public void ignoreJavaArrayOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void ignoreJavaArrayOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullFailFast.kt") + public void ignoreJavaCollectionOfExplicitNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNullFailFast.kt") + public void ignoreJavaCollectionOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void ignoreJavaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArrayFailFast.kt") + public void ignoreJavaCollectionOfNotNullToTypedArrayFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNullFailFast.kt") + public void ignoreJavaIteratorOfNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt"); + } + + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("javaArrayOfInheritedNotNull.kt") + public void testJavaArrayOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullable.kt") + public void testJavaArrayOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNull.kt") + public void testJavaCollectionOfExplicitNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullable.kt") + public void testJavaCollectionOfExplicitNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNull.kt") + public void testJavaCollectionOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullable.kt") + public void testJavaCollectionOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlib.kt") + public void testJavaCollectionOfNotNullFromStdlib() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlibToTypedArray.kt") + public void testJavaCollectionOfNotNullFromStdlibToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArray.kt") + public void testJavaCollectionOfNotNullToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt"); + } + + @TestMetadata("javaIteratorOfNotNull.kt") + public void testJavaIteratorOfNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractLightAnalysisModeTest { + @TestMetadata("javaArrayOfInheritedNotNullWithIndexFailFast.kt") + public void ignoreJavaArrayOfInheritedNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void ignoreJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndexFailFast.kt") + public void ignoreJavaCollectionOfExplicitNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void ignoreJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndexFailFast.kt") + public void ignoreJavaIteratorOfNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt"); + } + + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndex.kt") + public void testJavaArrayOfInheritedNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndex.kt") + public void testJavaArrayOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndex.kt") + public void testJavaCollectionOfExplicitNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullableWithIndex.kt") + public void testJavaCollectionOfExplicitNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndex.kt") + public void testJavaCollectionOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndex.kt") + public void testJavaIteratorOfNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 2851b11a1b8..cad7742ebaa 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -19413,6 +19413,192 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("javaArrayOfInheritedNotNull.kt") + public void testJavaArrayOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullFailFast.kt") + public void testJavaArrayOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullable.kt") + public void testJavaArrayOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNull.kt") + public void testJavaCollectionOfExplicitNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullFailFast.kt") + public void testJavaCollectionOfExplicitNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullable.kt") + public void testJavaCollectionOfExplicitNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNull.kt") + public void testJavaCollectionOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNullFailFast.kt") + public void testJavaCollectionOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullable.kt") + public void testJavaCollectionOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlib.kt") + public void testJavaCollectionOfNotNullFromStdlib() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlibToTypedArray.kt") + public void testJavaCollectionOfNotNullFromStdlibToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArray.kt") + public void testJavaCollectionOfNotNullToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArrayFailFast.kt") + public void testJavaCollectionOfNotNullToTypedArrayFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNull.kt") + public void testJavaIteratorOfNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt"); + } + + @TestMetadata("javaIteratorOfNotNullFailFast.kt") + public void testJavaIteratorOfNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndex.kt") + public void testJavaArrayOfInheritedNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndexFailFast.kt") + public void testJavaArrayOfInheritedNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndex.kt") + public void testJavaArrayOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndex.kt") + public void testJavaCollectionOfExplicitNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndexFailFast.kt") + public void testJavaCollectionOfExplicitNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullableWithIndex.kt") + public void testJavaCollectionOfExplicitNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndex.kt") + public void testJavaCollectionOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndex.kt") + public void testJavaIteratorOfNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndexFailFast.kt") + public void testJavaIteratorOfNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 071b7402ee0..ef59010f2bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -19413,6 +19413,192 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("javaArrayOfInheritedNotNull.kt") + public void testJavaArrayOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNull.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullFailFast.kt") + public void testJavaArrayOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullable.kt") + public void testJavaArrayOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaArrayOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNull.kt") + public void testJavaCollectionOfExplicitNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNull.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullFailFast.kt") + public void testJavaCollectionOfExplicitNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullable.kt") + public void testJavaCollectionOfExplicitNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfExplicitNullable.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNull.kt") + public void testJavaCollectionOfInheritedNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNull.kt"); + } + + @TestMetadata("javaCollectionOfInheritedNotNullFailFast.kt") + public void testJavaCollectionOfInheritedNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfInheritedNotNullFailFast.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullable.kt") + public void testJavaCollectionOfMaybeNullable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfMaybeNullableWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlib.kt") + public void testJavaCollectionOfNotNullFromStdlib() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlib.kt"); + } + + @TestMetadata("javaCollectionOfNotNullFromStdlibToTypedArray.kt") + public void testJavaCollectionOfNotNullFromStdlibToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullFromStdlibToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArray.kt") + public void testJavaCollectionOfNotNullToTypedArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArray.kt"); + } + + @TestMetadata("javaCollectionOfNotNullToTypedArrayFailFast.kt") + public void testJavaCollectionOfNotNullToTypedArrayFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaCollectionOfNotNullToTypedArrayFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNull.kt") + public void testJavaIteratorOfNotNull() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNull.kt"); + } + + @TestMetadata("javaIteratorOfNotNullFailFast.kt") + public void testJavaIteratorOfNotNullFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/javaIteratorOfNotNullFailFast.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndex.kt") + public void testJavaArrayOfInheritedNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndex.kt"); + } + + @TestMetadata("javaArrayOfInheritedNotNullWithIndexFailFast.kt") + public void testJavaArrayOfInheritedNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfInheritedNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndex.kt") + public void testJavaArrayOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaArrayOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndex.kt") + public void testJavaCollectionOfExplicitNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNotNullWithIndexFailFast.kt") + public void testJavaCollectionOfExplicitNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNotNullWithIndexFailFast.kt"); + } + + @TestMetadata("javaCollectionOfExplicitNullableWithIndex.kt") + public void testJavaCollectionOfExplicitNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfExplicitNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndex.kt") + public void testJavaCollectionOfMaybeNullableWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndex.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariable.kt"); + } + + @TestMetadata("javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt") + public void testJavaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaCollectionOfMaybeNullableWithIndexWithNotNullLoopVariableFailFast.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndex.kt") + public void testJavaIteratorOfNotNullWithIndex() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndex.kt"); + } + + @TestMetadata("javaIteratorOfNotNullWithIndexFailFast.kt") + public void testJavaIteratorOfNotNullWithIndexFailFast() throws Exception { + runTest("compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 68679a3f046..a267bea973d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -16509,6 +16509,32 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 45ba8d74b19..a78439295d2 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -17689,6 +17689,32 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaInterop extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInJavaInterop() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("compiler/testData/codegen/box/ranges/javaInterop/withIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithIndex extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/javaInterop/withIndex"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + } + } + @TestMetadata("compiler/testData/codegen/box/ranges/literal") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)