[Test] Add regression tests for issues which are fixed in K2

Related issues:
KT-10879, KT-18055, KT-20617, KT-23873
KT-25668, KT-31191, KT-33108, KT-41013
KT-51827, KT-53886, KT-56624, KT-58447
KT-58458, KT-58751, KT-58814, KT-60597
KT-62806, KT-63258, KT-63444, KT-65101
KT-65408, KT-65844, KT-66186

^KT-65926 Fixed
This commit is contained in:
Dmitriy Novozhilov
2024-02-28 12:13:45 +02:00
committed by Space Team
parent b875ae774e
commit 4b5eac7816
79 changed files with 1719 additions and 0 deletions
@@ -0,0 +1,14 @@
// ISSUE: KT-65844
@RequiresOptIn
annotation class MyOptIn
@MyOptIn
fun foo() {}
@OptIn(markerClass = [MyOptIn::class]) // should be ok
class MyClass {
fun test() {
foo()
}
}
@@ -0,0 +1,14 @@
// ISSUE: KT-65844
@RequiresOptIn
annotation class MyOptIn
@MyOptIn
fun foo() {}
@OptIn(markerClass = [<!OPT_IN_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_OPT_IN!>MyOptIn<!>::class]) // should be ok
class MyClass {
fun test() {
foo()
}
}
@@ -0,0 +1 @@
java.lang.AssertionError: Recursion detected on input: component2
@@ -0,0 +1,5 @@
// FIR_IDENTICAL
// WITH_STDLIB
// ISSUE: KT-58447
fun @ParameterName(<!UNRESOLVED_REFERENCE!>component2<!>) Int.component2() = this + 2
@@ -0,0 +1,10 @@
// ISSUE: KT-33108
// FULL_JDK
import java.util.Optional
open class A
class B : A()
fun useOptional(): A {
return Optional.of(0).map { B() as A }.orElse(A())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-33108
// FULL_JDK
import java.util.Optional
open class A
class B : A()
fun useOptional(): A {
return Optional.of(0).map { B() <!USELESS_CAST!>as A<!> }.orElse(A())
}
@@ -0,0 +1,15 @@
// ISSUE: KT-23873
// WITH_STDLIB
data class Holder<T>(val data: T)
val data: Map<Holder<Holder<*>>, Int> = null!!
val test = Holder(Holder(1))
fun test_1() {
data.get(test as Holder<*>)
}
fun test_2() {
data[test as Holder<*>]
}
@@ -0,0 +1,15 @@
// ISSUE: KT-23873
// WITH_STDLIB
data class Holder<T>(val data: T)
val data: Map<Holder<Holder<*>>, Int> = null!!
val test = Holder(Holder(1))
fun test_1() {
data.get(test as Holder<*>)
}
fun test_2() {
data[test <!USELESS_CAST!>as Holder<*><!>]
}
@@ -0,0 +1,7 @@
// ISSUE: KT-65408
data object CreateBuilder : Builder<CreateBuilder> {
fun foo(): CreateBuilder = <!UNRESOLVED_REFERENCE!>copy<!>() // should be an error
}
interface Builder<T> : Cloneable
@@ -0,0 +1,7 @@
// ISSUE: KT-65408
data object CreateBuilder : Builder<CreateBuilder> {
fun foo(): CreateBuilder = copy() // should be an error
}
interface Builder<T> : Cloneable
@@ -0,0 +1,8 @@
// ISSUE: KT-58751
class Result<out T>
interface Convert<T> {
fun convert(str: String): Result<T & Any>
}
fun Convert<*>.cnv(value: String): Result<Any> = convert(value)
@@ -0,0 +1,8 @@
// ISSUE: KT-58751
class Result<out T>
interface Convert<T> {
fun convert(str: String): Result<T & Any>
}
fun Convert<*>.cnv(value: String): Result<Any> = <!TYPE_MISMATCH!>convert(value)<!>
@@ -0,0 +1,5 @@
// ISSUE: KT-56624
import A as B
enum class A {
E()
}
@@ -0,0 +1,5 @@
// ISSUE: KT-56624
import A as B
enum class A {
E<!UNRESOLVED_REFERENCE!><!>()
}
@@ -0,0 +1,37 @@
// ISSUE: KT-65101
// WITH_STDLIB
interface Context<C: Context<C>>
interface InterfaceA<C: Context<C>>
class ABuilder<C: Context<C>, A: InterfaceA<C>, B: InterfaceA<C>>
operator fun <C, A, B> ABuilder<C, A, B>.invoke(block: B.() -> Unit): Unit
where C: Context<C>,
A: InterfaceA<C>,
B: InterfaceA<C>
= null!!
object ContextImpl : Context<ContextImpl>
object RootA : InterfaceA<ContextImpl>
class AImpl<P: Context<P>> : InterfaceA<P> {
fun foo(): Int = null!!
}
val <C: Context<C>, A: InterfaceA<C>> A.impl get() = ABuilder<C, A, AImpl<C>>()
fun test_1() {
RootA.apply {
(impl) {
foo()
}
}
}
fun test_2() {
RootA.apply {
impl {
foo()
}
}
}
@@ -0,0 +1,37 @@
// ISSUE: KT-65101
// WITH_STDLIB
interface Context<C: Context<C>>
interface InterfaceA<C: Context<C>>
class ABuilder<C: Context<C>, A: InterfaceA<C>, B: InterfaceA<C>>
operator fun <C, A, B> ABuilder<C, A, B>.invoke(block: B.() -> Unit): Unit
where C: Context<C>,
A: InterfaceA<C>,
B: InterfaceA<C>
= null!!
object ContextImpl : Context<ContextImpl>
object RootA : InterfaceA<ContextImpl>
class AImpl<P: Context<P>> : InterfaceA<P> {
fun foo(): Int = null!!
}
val <C: Context<C>, A: InterfaceA<C>> A.impl get() = ABuilder<C, A, AImpl<C>>()
fun test_1() {
RootA.apply {
(impl) {
foo()
}
}
}
fun test_2() {
RootA.apply {
impl {
<!UNRESOLVED_REFERENCE!>foo<!>()
}
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-66186
// WITH_STDLIB
// FULL_JDK
fun test() {
val list = listOf("asd", "sda")
list.stream()
.filter(String::isNotEmpty)
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>collect<!>(<!UNRESOLVED_REFERENCE!>FakeClass<!>.toList())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-66186
// WITH_STDLIB
// FULL_JDK
fun test() {
val list = listOf("asd", "sda")
list.stream()
.filter(String::isNotEmpty)
.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>collect<!>(<!UNRESOLVED_REFERENCE!>FakeClass<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>toList<!>())
}
@@ -0,0 +1,10 @@
// ISSUE: KT-63444
class A<D : Any> {
inner class Ainner<DD : D?> {
fun innerFun() {}
}
fun test(w:Ainner<*>) {
w.innerFun()
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-63444
class A<D : Any> {
inner class Ainner<DD : D?> {
fun innerFun() {}
}
fun test(w:Ainner<*>) {
w.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>innerFun<!>()
}
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-20617
fun Int.function() = run {
this@function + 1
}
val Int.property1: Int
get() {
return run { this@property1 + 1 }
}
val Int.property2 get() = run {
this@property2 + 1
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-20617
fun Int.function() = run {
this@function + 1
}
val Int.property1: Int
get() {
return run { this@property1 + 1 }
}
val Int.property2 get() = run {
this<!UNRESOLVED_REFERENCE!>@property2<!> <!DEBUG_INFO_MISSING_UNRESOLVED!>+<!> 1
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-41013
fun <V, R> Iterable<V>.map(transform: (V) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v) }
}
fun <V, R> Iterable<V>.map(transform: (V, Int) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v, i) }
}
fun main() {
val list = listOf(1, 2, 3)
println(list.map { v -> v })
println(list.map { it })
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
// ISSUE: KT-41013
fun <V, R> Iterable<V>.map(transform: (V) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v) }
}
fun <V, R> Iterable<V>.map(transform: (V, Int) -> R): List<R> {
return this.mapIndexed { i, v -> transform(v, i) }
}
fun main() {
val list = listOf(1, 2, 3)
println(list.map { v -> v })
println(list.<!OVERLOAD_RESOLUTION_AMBIGUITY!>map<!> { <!UNRESOLVED_REFERENCE!>it<!> })
}
@@ -0,0 +1,20 @@
// ISSUE: KT-51827
abstract class A {
abstract protected val a: Any?
open class Nested(override val a: String) : A() {
class B {
fun f(other: A) {
other.a
if (other is Nested) {
other.a.length
}
if (other is C) {
other.a
}
}
}
}
class C(override val a: String): Nested(a)
}
@@ -0,0 +1,20 @@
// ISSUE: KT-51827
abstract class A {
abstract protected val a: Any?
open class Nested(override val a: String) : A() {
class B {
fun f(other: A) {
other.a
if (other is Nested) {
<!DEBUG_INFO_SMARTCAST!>other<!>.a.length
}
if (other is C) {
<!DEBUG_INFO_SMARTCAST!>other<!>.<!INVISIBLE_MEMBER!>a<!>
}
}
}
}
class C(override val a: String): Nested(a)
}
@@ -0,0 +1,16 @@
// FULL_JDK
// WITH_REFLECT
// ISSUE: KT-58814
open class A
class B : A()
class C : A()
fun <T : A> createObj(implementedBy: Class<T>): T {
val obj = when (implementedBy) {
B::class.java -> B()
else -> throw Exception("unsupported class")
}
val castObj = implementedBy.cast(obj)
return castObj // should be OK
}
@@ -0,0 +1,16 @@
// FULL_JDK
// WITH_REFLECT
// ISSUE: KT-58814
open class A
class B : A()
class C : A()
fun <T : A> createObj(implementedBy: Class<T>): T {
val obj = when (implementedBy) {
B::class.java -> B()
else -> throw Exception("unsupported class")
}
val castObj = <!DEBUG_INFO_SMARTCAST!>implementedBy<!>.cast(obj)
return <!TYPE_MISMATCH!>castObj<!> // should be OK
}
@@ -0,0 +1,17 @@
// ISSUE: KT-10879
// FILE: A.java
public interface A {
A getFoo();
}
// FILE: main.kt
interface B : A
interface C : A
fun test(x: A) {
if (x !is C) return
if (x is B) {
x.foo.foo
x.getFoo().foo
}
}
@@ -0,0 +1,17 @@
// ISSUE: KT-10879
// FILE: A.java
public interface A {
A getFoo();
}
// FILE: main.kt
interface B : A
interface C : A
fun test(x: A) {
if (x !is C) return
if (x is B) {
x.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>foo<!>
x.getFoo().foo
}
}
@@ -0,0 +1,13 @@
// ISSUE: KT-18055
fun main() {
data class Stat(val link: String? = null)
var stat = Stat()
if (stat.link != null) {
takeString(stat.link)
}
}
fun takeString(link: String) {}
@@ -0,0 +1,13 @@
// ISSUE: KT-18055
fun main() {
data class Stat(val link: String? = null)
var stat = Stat()
if (stat.link != null) {
takeString(<!SMARTCAST_IMPOSSIBLE!>stat.link<!>)
}
}
fun takeString(link: String) {}
@@ -0,0 +1,5 @@
java.lang.IllegalArgumentException: fromIndex(0) > toIndex(-1)
at java.util.ArrayList.subListRangeCheck(ArrayList.java:1016)
at java.util.ArrayList.subList(ArrayList.java:1006)
at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.quickResolveToPackage(QualifiedExpressionResolver.kt:708)
at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.resolveToPackageOrClassPrefix(QualifiedExpressionResolver.kt:527)
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
// ISSUE: KT-60597
fun test() {
<!UNRESOLVED_REFERENCE!>`java.lang.Short.TYPE`<!>.getConstructor(TODO())
}
@@ -0,0 +1,4 @@
java.lang.NullPointerException
at org.jetbrains.kotlin.types.expressions.PatternMatchingTypingVisitor$Subject$Variable.makeValueArgument(PatternMatchingTypingVisitor.kt:149)
at org.jetbrains.kotlin.types.expressions.PatternMatchingTypingVisitor$checkWhenCondition$1.visitWhenConditionInRange(PatternMatchingTypingVisitor.kt:509)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitWhenConditionInRange(KtVisitorVoid.java:1015)
@@ -0,0 +1,8 @@
// FIR_IDENTICAL
// ISSUE: KT-58458
fun box() =
when (val<!SYNTAX!><!> = <!UNRESOLVED_REFERENCE!>x<!>) {
in <!UNRESOLVED_REFERENCE!>y<!> -> ""
else -> ""
}
@@ -0,0 +1,14 @@
// ISSUE: KT-31191
import kotlin.contracts.*
@OptIn(ExperimentalContracts::class)
fun Any.isString(): Boolean {
contract { returns(true) implies (this@isString is String) }
return this is String
}
fun test(x: Any?) {
if (x != null && x.isString()) {
x.length
}
}
@@ -0,0 +1,14 @@
// ISSUE: KT-31191
import kotlin.contracts.*
@OptIn(ExperimentalContracts::class)
fun Any.isString(): Boolean {
contract { returns(true) implies (this@isString is String) }
return this is String
}
fun test(x: Any?) {
if (x != null && <!DEBUG_INFO_SMARTCAST!>x<!>.isString()) {
x.<!UNRESOLVED_REFERENCE!>length<!>
}
}
@@ -0,0 +1,10 @@
// ISSUE: KT-25668
suspend fun SequenceScope<Int>.bar() = yield(1)
fun test() {
val seq = sequence {
val f: suspend SequenceScope<Int>.() -> Unit = SequenceScope<Int>::bar
f()
}
seq.toList()
}
@@ -0,0 +1,10 @@
// ISSUE: KT-25668
suspend fun SequenceScope<Int>.bar() = yield(1)
fun test() {
val seq = sequence {
val f: suspend SequenceScope<Int>.() -> Unit = SequenceScope<Int>::<!ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL!>bar<!>
f()
}
seq.toList()
}