tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
class B1
|
||||
class B2(val x: Int)
|
||||
class B3(val x: Long, val y: Int)
|
||||
class B4(val str: String)
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
A.B1()
|
||||
val b2 = A.B2(A.B3(42, 42).y)
|
||||
return A.B4("OK").str
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun foo(f: (Int) -> Int) = f(0)
|
||||
|
||||
class Outer {
|
||||
class Nested {
|
||||
val y = foo { a -> a }
|
||||
}
|
||||
|
||||
fun bar(): String {
|
||||
val a = Nested()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer().bar()
|
||||
@@ -0,0 +1,31 @@
|
||||
class Outer {
|
||||
class Nested
|
||||
inner class Inner
|
||||
|
||||
fun Inner.foo() {
|
||||
Outer()
|
||||
Nested()
|
||||
Inner()
|
||||
}
|
||||
|
||||
fun Nested.bar() {
|
||||
Outer()
|
||||
Nested()
|
||||
Inner()
|
||||
}
|
||||
|
||||
fun Outer.baz() {
|
||||
Outer()
|
||||
Nested()
|
||||
Inner()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Inner().foo()
|
||||
Nested().bar()
|
||||
baz()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer().box()
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
class Nested {
|
||||
val value = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun Test.Nested.foo() = value
|
||||
|
||||
fun box() = Test.Nested().foo()
|
||||
@@ -0,0 +1,18 @@
|
||||
import A.B
|
||||
import A.B.C
|
||||
|
||||
class A {
|
||||
class B {
|
||||
class C
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val b = B()
|
||||
val ab = A.B()
|
||||
val c = C()
|
||||
val bc = B.C()
|
||||
val abc = A.B.C()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Outer {
|
||||
inner class Inner<T>(val t: T) {
|
||||
fun box() = t
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Outer().Inner("OK").box() != "OK") return "Fail"
|
||||
val x: Outer.Inner<String> = Outer().Inner("OK")
|
||||
return x.box()
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public abstract class JavaClass {
|
||||
public static String test() {
|
||||
return Test.INSTANCE.foo(new Outer<String>("OK").new Inner<Integer>(1));
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
|
||||
class Outer<E>(val x: E) {
|
||||
inner class Inner<F>(val y: F) {
|
||||
fun foo() = x.toString() + y.toString()
|
||||
}
|
||||
}
|
||||
|
||||
object Test {
|
||||
fun foo(x: Outer<String>.Inner<Integer>) = x.foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = JavaClass.test()
|
||||
if (result != "OK1") return "Fail: $result"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public abstract class JavaClass {
|
||||
public abstract InnerClass onCreateInner();
|
||||
|
||||
public class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Kotlin.kt
|
||||
|
||||
public class MyWallpaperService : JavaClass() {
|
||||
override fun onCreateInner(): JavaClass.InnerClass = MyEngine()
|
||||
|
||||
private inner class MyEngine : JavaClass.InnerClass()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (MyWallpaperService().onCreateInner() != null) return "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
fun O() = this@Outer.O
|
||||
val K = this@Outer.K()
|
||||
}
|
||||
|
||||
val O = "O"
|
||||
fun K() = "K"
|
||||
}
|
||||
|
||||
fun box() = Outer().Inner().O() + Outer().Inner().K
|
||||
@@ -0,0 +1,7 @@
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
fun box() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer().Inner().box()
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
interface Foo { }
|
||||
|
||||
class FooImplNested: Foo { }
|
||||
|
||||
inner class FooImplInner: Foo { }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Test().FooImplInner()
|
||||
Test.FooImplNested()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//KT-3927 Inner class cannot be instantiated with child instance of outer class
|
||||
|
||||
abstract class Base {
|
||||
inner class Inner {
|
||||
fun o() = "O"
|
||||
fun k() = "K"
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Base()
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
result += Child().Inner().o()
|
||||
|
||||
fun Child.f() {
|
||||
result += Inner().k()
|
||||
}
|
||||
Child().f()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Outer {
|
||||
class Nested{
|
||||
fun foo(s: String) = s.extension()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun String.extension(): String = this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Outer.Nested().foo("OK")
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Outer {
|
||||
class Nested {
|
||||
fun fn() = s
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val s = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Outer.Nested().fn()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
object A {
|
||||
class B
|
||||
class C<T>
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = A.B()
|
||||
val c = A.C<String>()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Outer {
|
||||
class Nested {
|
||||
companion object {
|
||||
val O = "O"
|
||||
val K = "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun O() = Nested.O
|
||||
}
|
||||
|
||||
fun box() = Outer().O() + Outer.Nested.K
|
||||
@@ -0,0 +1,8 @@
|
||||
class Outer {
|
||||
enum class Nested {
|
||||
O,
|
||||
K
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = "${Outer.Nested.O}${Outer.Nested.K}"
|
||||
@@ -0,0 +1,12 @@
|
||||
class Outer {
|
||||
class Nested<T>(val t: T) {
|
||||
fun box() = t
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Outer.Nested<String>("OK").box() != "OK") return "Fail"
|
||||
|
||||
val x: Outer.Nested<String> = Outer.Nested("OK")
|
||||
return x.box()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package Package
|
||||
|
||||
class Outer {
|
||||
class Nested {
|
||||
val O = "O"
|
||||
val K = "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Package.Outer.Nested().O + Outer.Nested().K
|
||||
@@ -0,0 +1,9 @@
|
||||
object A {
|
||||
object B {
|
||||
object C {
|
||||
val ok = "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A.B.C.ok
|
||||
@@ -0,0 +1,7 @@
|
||||
class Outer {
|
||||
class Nested {
|
||||
fun box() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer.Nested().box()
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// See KT-9246 IllegalAccessError when trying to access protected nested class from parent class
|
||||
// FILE: a.kt
|
||||
|
||||
package a
|
||||
|
||||
abstract class A {
|
||||
protected class C {
|
||||
fun result() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
package b
|
||||
|
||||
import a.A
|
||||
|
||||
class B : A() {
|
||||
protected val c = A.C()
|
||||
val result: String get() = c.result()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return B().result
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// See KT-8269 java.lang.IllegalAccessError on accessing protected inner class declared in Kotlin super class
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: Test.kt
|
||||
|
||||
package com.company
|
||||
|
||||
import other.JavaClass
|
||||
|
||||
open class Test {
|
||||
protected class ProtectedClass
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
JavaClass.test()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: other/JavaClass.java
|
||||
|
||||
package other;
|
||||
|
||||
import com.company.Test;
|
||||
|
||||
public class JavaClass {
|
||||
static class JavaTest extends Test {
|
||||
public static boolean foo(Object obj) {
|
||||
return obj instanceof ProtectedClass;
|
||||
}
|
||||
}
|
||||
|
||||
public static void test() {
|
||||
JavaTest.foo(new Object());
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
open class A(val s: String) {
|
||||
open inner class B(s: String): A(s)
|
||||
|
||||
open inner class C(s: String, additional: Double): B(s)
|
||||
|
||||
open inner class D(other: Int, another: Long, s: String) : C(s, another.toDouble())
|
||||
|
||||
open inner class E : D(0, 42L, "OK")
|
||||
|
||||
inner class F : E()
|
||||
}
|
||||
|
||||
fun box(): String = A("Fail").F().s
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
fun box(): String {
|
||||
abstract class L1 {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
open class L2(val s: String) : L1() {
|
||||
override fun foo() = s
|
||||
}
|
||||
|
||||
open class L3(unused: Double, value: String = "OK") : L2(value)
|
||||
|
||||
open class L4(i: Int, j: Long, z: Boolean, l: L3) : L3(3.14)
|
||||
|
||||
class L5 : L4(0, 0L, false, L3(2.71, "Fail"))
|
||||
|
||||
return L5().foo()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
open class Father(val param: String) {
|
||||
abstract inner class InClass {
|
||||
fun work(): String {
|
||||
return param
|
||||
}
|
||||
}
|
||||
|
||||
inner class Child(p: String) : Father(p) {
|
||||
inner class Child2 : Father.InClass {
|
||||
constructor(): super()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Father("fail").Child("OK").Child2().work()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
open class Father(val param: String) {
|
||||
abstract inner class InClass {
|
||||
fun work(): String {
|
||||
return param
|
||||
}
|
||||
}
|
||||
|
||||
inner class Child(p: String) : Father(p) {
|
||||
inner class Child2 : Father.InClass() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Father("fail").Child("OK").Child2().work()
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// When inner class extends its outer, there are two instances of the outer present in the inner:
|
||||
// the enclosing one and the one in the super call.
|
||||
// Here we test that symbols are resolved to the instance created via the super call.
|
||||
|
||||
open class Outer(vararg val chars: Char) {
|
||||
open inner class Inner(val s: String): Outer(s[0], s[1]) {
|
||||
fun concat() = java.lang.String.valueOf(chars)
|
||||
}
|
||||
|
||||
fun value() = Inner("OK").concat()
|
||||
}
|
||||
|
||||
fun box() = Outer('F', 'a', 'i', 'l').value()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
abstract class Father {
|
||||
abstract inner class InClass {
|
||||
abstract fun work(): String
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Father() {
|
||||
val ChildInClass = object : Father.InClass() {
|
||||
override fun work(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Child().ChildInClass.work()
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
abstract class Father {
|
||||
abstract inner class InClass {
|
||||
abstract fun work(): String
|
||||
}
|
||||
}
|
||||
|
||||
class Child : Father() {
|
||||
fun test(): InClass {
|
||||
return object : Father.InClass() {
|
||||
override fun work(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Child().test().work()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class A {
|
||||
fun bar(): Any {
|
||||
return {
|
||||
{
|
||||
class Local : Inner() {
|
||||
override fun toString() = foo()
|
||||
}
|
||||
Local()
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
open inner class Inner
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = A().bar().toString()
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
open class Father(val param: String) {
|
||||
abstract inner class InClass {
|
||||
fun work(): String {
|
||||
return param
|
||||
}
|
||||
}
|
||||
|
||||
inner class Child(p: String) : Father(p) {
|
||||
fun test(): InClass {
|
||||
class Local : Father.InClass() {
|
||||
|
||||
}
|
||||
return Local()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Father("fail").Child("OK").test().work()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
open class Local(val ok: Boolean) {
|
||||
fun result() = if (ok) result else "Fail"
|
||||
}
|
||||
|
||||
class Derived : Local(true)
|
||||
|
||||
return Derived().result()
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
fun box(): String {
|
||||
val three = 3
|
||||
|
||||
open class Local(val one: Int) {
|
||||
open fun value() = "$three$one"
|
||||
}
|
||||
|
||||
val four = 4
|
||||
|
||||
class Derived(val two: Int) : Local(1) {
|
||||
override fun value() = super.value() + "$four$two"
|
||||
}
|
||||
|
||||
val result = Derived(2).value()
|
||||
return if (result == "3142") "OK" else "Fail: $result"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// KT-3581
|
||||
|
||||
open class A(val result: String = "OK") {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = object : A() {}
|
||||
return a.result
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class SomeClass(val some: Double, val other: Int, vararg val args: String) {
|
||||
fun result() = args[1]
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return object : SomeClass(3.14, 42, "No", "OK", "Yes") {
|
||||
}.result()
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
open inner class Inner(val result: String)
|
||||
|
||||
fun box(): String {
|
||||
val o = object : Inner("OK") {
|
||||
fun ok() = result
|
||||
}
|
||||
return o.ok()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().box()
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
open inner class Inner(val result: String = "OK", val int: Int)
|
||||
|
||||
fun box(): String {
|
||||
val o = object : Inner(int = 0) {
|
||||
fun ok() = result
|
||||
}
|
||||
return o.ok()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().box()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
fun box(): String {
|
||||
val capture = "oh"
|
||||
|
||||
class Local {
|
||||
val captured = capture
|
||||
|
||||
open inner class Inner(val d: Double = -1.0, val s: String, vararg val y: Int) {
|
||||
open fun result() = "Fail"
|
||||
}
|
||||
|
||||
val obj = object : Inner(s = "OK") {
|
||||
override fun result() = s
|
||||
}
|
||||
}
|
||||
|
||||
return Local().obj.result()
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
fun box(): String {
|
||||
class Local {
|
||||
open inner class Inner(val s: String) {
|
||||
open fun result() = "Fail"
|
||||
}
|
||||
|
||||
val realResult = "OK"
|
||||
|
||||
val obj = object : Inner(realResult) {
|
||||
override fun result() = s
|
||||
}
|
||||
}
|
||||
|
||||
return Local().obj.result()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
open class A(val s: String)
|
||||
|
||||
fun box(): String {
|
||||
class B {
|
||||
val result = "OK"
|
||||
|
||||
val f = object : A(result) {}.s
|
||||
}
|
||||
|
||||
return B().f
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun box(): String {
|
||||
val d = 42.0
|
||||
val c = 'C'
|
||||
|
||||
open class Local(val l: Long) {
|
||||
fun foo(): Boolean = d == 42.0 && c == 'C' && l == 239L
|
||||
}
|
||||
|
||||
if (object : Local(239L) {
|
||||
fun bar(): Boolean = foo()
|
||||
}.bar()) return "OK"
|
||||
|
||||
return "Fail"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class A {
|
||||
fun bar(): Any {
|
||||
return {
|
||||
{
|
||||
object : Inner() {
|
||||
override fun toString() = foo()
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
open inner class Inner
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = A().bar().toString()
|
||||
Reference in New Issue
Block a user