[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,6 @@
interface My
internal class Your: My
// Code is valid, despite of delegate is internal
class His: My by Your()
@@ -0,0 +1,12 @@
// KT-14469: SOE during effective visibility evaluation
abstract class Base(private val v: String)
fun bar(arg: String) = arg
class Derived : Base("123") {
private inline fun foo() {
bar(<!INAPPLICABLE_CANDIDATE!>v<!>)
}
}
@@ -0,0 +1,12 @@
internal class My
class Your
// Both arguments should be exposed
fun foo(my: My, f: (My) -> Unit) = f(my)
// Ok
fun bar(your: Your, f: (Your) -> Unit) = f(your)
// Exposed, returns My
fun gav(f: () -> My) = f()
@@ -0,0 +1,4 @@
private interface My
// valid, it's allowed to implement worse-visible interface
class Your: My
@@ -0,0 +1,89 @@
// !DIAGNOSTICS: -USELESS_CAST -UNUSED_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
// FILE: j/Base.java
package j;
public interface Base {
void foo();
}
// FILE: j/Impl.java
package j;
/* package */ abstract class Impl implements Base {
public void foo() {}
}
// FILE: j/Derived1.java
package j;
public class Derived1 extends Impl {}
// FILE: j/Derived2.java
package j;
public class Derived2 extends Impl {}
// FILE: k/Client.kt
package k
import j.*
val d1 = Derived1()
val d2 = Derived2()
fun <T> select(x1: T, x2: T) = x1
fun <T> selectn(vararg xx: T) = xx[0]
fun <T : Base> foo(x: T) = x.foo()
fun <T> listOf2(x1: T, x2: T): List<T> = null!!
fun <T> arrayOf2(x1: T, x2: T): Array<T> = null!!
fun test() {
val test1: Base = if (true) d1 else d2
val test2 = if (true) d1 else d2
val test3 = when {
true -> d1
else -> d2
}
val test4: Base = when {
true -> d1
else -> d2
}
val test5 = select(d1, d2)
val test6 = select<Base>(d1, d2)
val test7 = select(d1 as Base, d2)
val test8 = selectn(d1, d2)
val test9 = selectn<Base>(d1, d2)
val test10 = listOf2(d1, d2)
val test11: List<Base> = listOf2(d1, d2)
// NB Inferred type is List<Impl> because List is covariant.
val test12 = listOf2<Base>(d1, d2)
val test13 = arrayOf2(d1, d2)
val test14: Array<Base> = arrayOf2(d1, d2)
// NB Inferred type is Array<Base> because Array is invariant.
val test15 = arrayOf2<Base>(d1, d2)
for (test16 in listOf2(d1, d2)) {}
}
fun testOkInJava() {
// The following is Ok in Java, but is an error in Kotlin.
// TODO do not generate unneeded CHECKCASTs.
// TODO do not report INACCESSIBLE_TYPE for corresponding cases.
select(d1, d2)
foo(select(d1, d2))
}
@@ -0,0 +1,25 @@
internal open class My
// valid, internal from internal
internal open class Your: My() {
// valid, effectively internal
fun foo() = My()
}
// error, public from internal
open class His: Your() {
protected open class Nested
// error, public from internal
val x = My()
// valid, private from internal
private fun bar() = My()
// valid, internal from internal
internal var y: My? = null
// error, protected from internal
protected fun baz() = Your()
}
internal class Their: His() {
// error, effectively internal from protected
class InnerDerived: His.Nested()
}
@@ -0,0 +1,10 @@
public open class A {
protected open class B
}
public open class C : A() {
protected open class D {
// internal & protected(in C) <= protected(in A): Ok
internal open class E : A.B()
}
}
@@ -0,0 +1,10 @@
interface Your
class My {
internal val x = object : Your {}
internal fun foo() = <!UNRESOLVED_REFERENCE!>{
class Local
Local()
}()<!>
}
@@ -0,0 +1,18 @@
// invalid, depends on local class
fun foo() = run {
class A
A()
}
// invalid, depends on local class
fun gav() = {
class B
B()
}
abstract class My
// valid, object literal here is effectively My
fun bar() = run {
object: My() {}
}
@@ -0,0 +1,7 @@
class My {
internal open class ThreadLocal
// Private from local: ???
private val values =
// Local from internal: Ok
object: ThreadLocal() {}
}
@@ -0,0 +1,15 @@
class A {
private open class B
fun f() {
// Local from private: Ok
class C : B()
}
}
private open class D
fun f(): Int {
// Local from private: Ok
val x = object : D() { }
return x.hashCode()
}
@@ -0,0 +1,60 @@
class My<T>(val value: T)
open class Base
fun invalid1() = run {
class Local
My(Local())
}
fun invalid2() = My(object {})
fun invalid3() = My(object : Base() {})
fun invalid4() = run {
class Local
My(My(Local()))
}
fun invalid5() = run {
fun invalid5a() = run {
class Local
Local()
}
My(invalid5a())
}
// Valid: effectively Any
fun valid1() = object {}
// Valid: effectively Base
fun valid2() = object : Base() {}
// Valid: explicit type argument
fun valid3() = My<Base>(object : Base() {})
// Valid: explicit type specified
fun valid4() : My<Base> = My(object : Base() {})
// Valid: local class denotable in local scope
fun valid5() = run {
class Local
fun valid5a() = My(Local())
My<Any>(valid5a())
}
// Valid: local class denotable in local scope
fun valid6() = run {
class Local
fun valid6a() = run {
fun valid6b() = My(Local())
valid6b()
}
My<Any>(valid6a())
}
// Valid: effectively My<Any>
fun valid7() = run {
class Local
My<My<*>>(My(Local()))
}
@@ -0,0 +1,21 @@
class Something {
public val publicVal1 = object { override fun toString() = "!" }
protected val protectedVal1 = object { override fun toString() = "!" }
internal val internalVal1 = object { override fun toString() = "!" }
private val privateVal1 = object { override fun toString() = "!" }
public val publicVal2 = run { class A; A() }
protected val protectedVal2 = run { class A; A() }
internal val internalVal2 = run { class A; A() }
private val privateVal2 = run { class A; A() }
public fun publicFun1() = object { override fun toString() = "!" }
protected fun protectedFun1() = object { override fun toString() = "!" }
internal fun internalFun1() = object { override fun toString() = "!" }
private fun privateFun1() = object { override fun toString() = "!" }
public fun publicFun2() = run { class A; A() }
protected fun protectedFun2() = run { class A; A() }
internal fun internalFun2() = run { class A; A() }
private fun privateFun2() = run { class A; A() }
}
@@ -0,0 +1,60 @@
class My<T>(val value: T)
open class Base
val invalid1 = run {
class Local
My(Local())
}
val invalid2 = My(object {})
val invalid3 = My(object : Base() {})
val invalid4 = run {
class Local
My(My(Local()))
}
val invalid5 = run {
fun invalid5a() = run {
class Local
Local()
}
My(invalid5a())
}
// Valid: effectively Any
val valid1 = object {}
// Valid: effectively Base
val valid2 = object : Base() {}
// Valid: explicit type argument
val valid3 = My<Base>(object : Base() {})
// Valid: explicit type specified
val valid4 : My<Base> = My(object : Base() {})
// Valid: local class denotable in local scope
val valid5 = run {
class Local
fun valid5a() = My(Local())
My<Any>(valid5a())
}
// Valid: local class denotable in local scope
val valid6 = run {
class Local
fun valid6a() = run {
fun valid6b() = My(Local())
valid6b()
}
My<Any>(valid6a())
}
// Valid: effectively My<Any>
val valid7 = run {
class Local
My<My<*>>(My(Local()))
}
@@ -0,0 +1,6 @@
internal open class My
internal class Outer {
// Ok, effectively internal from internal
class Your: My()
}
@@ -0,0 +1,30 @@
// From KT-10753
object My : Inter() {
fun foo(arg: Inter): Inter = arg
val x: Inter? = null
}
internal open class Inter
// From KT-10799
open class Test {
protected class Protected
fun foo(x: Protected) = x
interface NestedInterface {
fun create(x: Protected)
}
class NestedClass {
fun create(x: Protected) = x
}
object NestedObject {
fun create(x: Protected) = x
}
companion object {
fun create(x: Protected) = x
}
}
@@ -0,0 +1,35 @@
// JAVAC_EXPECTED_FILE
// FILE: test/My.java
package test;
class Internal {}
public class My {
static public Internal foo() { return new Internal(); }
}
// FILE: test/His.kt
package test
class His {
// Ok: private vs package-private
private fun private() = My.foo()
// Ok: internal vs package-private in same package
internal fun internal() = My.foo()
// Error: protected vs package-private
protected fun protected() = My.foo()
// Error: public vs package-private
fun public() = My.foo()
}
// FILE: other/Your.kt
package other
import test.My
class Your {
internal fun bar() = My.foo()
}
@@ -0,0 +1,12 @@
interface Your
class My {
// private from local: ???
private val x = object : Your {}
// private from local: ???
private fun foo() = <!UNRESOLVED_REFERENCE!>{
class Local
Local()
}()<!>
}
@@ -0,0 +1,3 @@
private enum class Foo { A, B }
class Bar private constructor(private val foo: Foo)
@@ -0,0 +1,3 @@
private enum class Foo { A, B }
private class Bar(val foo: Foo)
@@ -0,0 +1,3 @@
private enum class Foo { A, B }
class Bar private constructor(val foo: Foo)
@@ -0,0 +1,3 @@
private enum class Foo { A, B }
class Bar(val foo: Foo)
@@ -0,0 +1,20 @@
open class A {
// protected relative to A
protected open class B {
fun foo() {}
}
public open class C {
// protected relative to C, must be an error
protected open class D : B()
}
}
class E : A.C() {
// F has invisible grandparent class B (E does not inherit from A)
class F : A.C.D() {
init {
// Invoke function from invisible grandparent
foo()
}
}
}
@@ -0,0 +1,12 @@
// See KT-9540
// all protected should have lower bound that is more permissive than private
// protected and internal should have lower bound that is more permissive than private
open class A {
private interface B
protected open class C {
protected interface D : B
internal interface E : B, D
}
}
@@ -0,0 +1,16 @@
// FILE: Outer.java
public abstract class Outer {
protected static class My {}
protected static class Your extends My {}
abstract protected Your foo(My my);
}
// FILE: OuterDerived.kt
class OuterDerived: Outer() {
// valid, My has better visibility
protected class His: Outer.My()
// valid, My and Your have better visibility
override fun foo(my: Outer.My) = Outer.Your()
}
@@ -0,0 +1,13 @@
abstract class Outer {
protected open class My
// Both valid: same way protected
protected class Your: My()
abstract protected fun foo(my: My): Your
}
class OuterDerived: Outer() {
// valid, My has better visibility
protected class His: Outer.My()
// valid, My and Your have better visibility
override fun foo(my: Outer.My) = Outer.Your()
}
@@ -0,0 +1,23 @@
private interface My
private open class Base
public interface Your: My {
fun <T: Base> foo(): T
}
public class Derived<T: My>(val x: My): Base() {
constructor(xx: My?, x: My): this(xx ?: x)
val y: Base? = null
val My.z: Int
get() = 42
fun foo(m: My): My = m
fun My.bar(): My = this
}
@@ -0,0 +1,17 @@
internal open class My
abstract class Your {
// invalid, List<My> is effectively internal
abstract fun give(): List<My>
}
// invalid, List<My> is effectively internal
interface His: List<My>
// invalid, My is internal
interface Generic<E: My>
interface Our {
// invalid, Generic<My> is effectively internal
fun foo(): Generic<*>
}