tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
var a: String = "Fail"
|
||||
|
||||
init {
|
||||
a = object {
|
||||
override fun toString(): String = "OK"
|
||||
}.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class A(
|
||||
val a: String = object {
|
||||
override fun toString(): String = "OK"
|
||||
}.toString()
|
||||
)
|
||||
|
||||
fun box() : String {
|
||||
return A().a
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// Enable for JVM backend when KT-8120 gets fixed
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class C() {
|
||||
val y = t
|
||||
|
||||
inner class D() {
|
||||
fun copyOuter() = C()
|
||||
}
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = C()
|
||||
}
|
||||
|
||||
val c = (s as C).D().copyOuter()
|
||||
log += c.y
|
||||
}
|
||||
|
||||
if (log != "111") return "fail: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class A() {
|
||||
fun foo() = { t }
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = A()
|
||||
}
|
||||
|
||||
log += (s as A).foo()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail1: ${log}"
|
||||
|
||||
s = null
|
||||
log = ""
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class B() {
|
||||
val y = t
|
||||
|
||||
fun foo() = { y }
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = B()
|
||||
}
|
||||
|
||||
log += (s as B).foo()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail2: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
// Enable for JVM backend when KT-8120 gets fixed
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
fun box(): String {
|
||||
val capturedInConstructor = 1
|
||||
val capturedInBody = 10
|
||||
var log = ""
|
||||
|
||||
class A(var x: Int) {
|
||||
var y = 0
|
||||
|
||||
fun copy(): A {
|
||||
log += "A.copy;"
|
||||
val result = A(x)
|
||||
result.y += capturedInBody
|
||||
return result
|
||||
}
|
||||
|
||||
init {
|
||||
log += "A.<init>;"
|
||||
y += x + capturedInConstructor
|
||||
}
|
||||
}
|
||||
|
||||
val a = A(100).copy()
|
||||
if (a.y != 111) return "fail1a: ${a.y}"
|
||||
if (a.x != 100) return "fail1b: ${a.x}"
|
||||
|
||||
|
||||
class B(var x: Int) {
|
||||
var y = 0
|
||||
|
||||
fun copier(): () -> B {
|
||||
log += "B.copier;"
|
||||
return {
|
||||
log += "B.copy;"
|
||||
val result = B(x)
|
||||
result.y += capturedInBody
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
y += x + capturedInConstructor
|
||||
log += "B.<init>;"
|
||||
}
|
||||
}
|
||||
|
||||
val b = B(100).copier()()
|
||||
if (b.y != 111) return "fail2a: ${b.y}"
|
||||
if (b.x != 100) return "fail2b: ${b.x}"
|
||||
|
||||
class C(var x: Int) {
|
||||
var y = 0
|
||||
|
||||
inner class D() {
|
||||
fun copyOuter(): C {
|
||||
log += "D.copyOuter;"
|
||||
val result = C(x)
|
||||
result.y += capturedInBody
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
log += "C.<init>;"
|
||||
y += x + capturedInConstructor
|
||||
}
|
||||
}
|
||||
|
||||
val c = C(100).D().copyOuter()
|
||||
if (c.y != 111) return "fail3a: ${c.y}"
|
||||
if (c.x != 100) return "fail3b: ${c.x}"
|
||||
|
||||
if (log != "A.<init>;A.copy;A.<init>;B.<init>;B.copier;B.copy;B.<init>;C.<init>;D.copyOuter;C.<init>;") return "fail_log: $log"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
fun A.a(): String {
|
||||
class B {
|
||||
val b : String
|
||||
get() = this@a.s
|
||||
}
|
||||
return B().b
|
||||
}
|
||||
|
||||
class A {
|
||||
val s : String = "OK"
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a()
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package test
|
||||
|
||||
val A.a: String
|
||||
get() {
|
||||
class B {
|
||||
val b : String
|
||||
get() = this@a.s
|
||||
}
|
||||
return B().b
|
||||
}
|
||||
|
||||
class A {
|
||||
val s : String = "OK"
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package test
|
||||
|
||||
class C(val s : String) {
|
||||
fun A.a(): String {
|
||||
class B {
|
||||
val b : String
|
||||
get() = this@a.s + this@C.s
|
||||
}
|
||||
return B().b
|
||||
}
|
||||
|
||||
fun test(a : A) : String {
|
||||
return a.a()
|
||||
}
|
||||
}
|
||||
|
||||
class A(val s: String) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return C("K").test(A("O"))
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package test
|
||||
|
||||
class C(val s : String) {
|
||||
val A.a: String
|
||||
get() {
|
||||
class B {
|
||||
val b : String
|
||||
get() = this@a.s + this@C.s
|
||||
}
|
||||
return B().b
|
||||
}
|
||||
|
||||
fun test(a : A) : String {
|
||||
return a.a
|
||||
}
|
||||
}
|
||||
|
||||
class A(val s: String) {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return C("K").test(A("O"))
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class A {
|
||||
val a = 1
|
||||
fun calc () : Int {
|
||||
class B() {
|
||||
val b = 2
|
||||
inner class C {
|
||||
val c = 3
|
||||
fun calc() = this@A.a + this@B.b + this.c
|
||||
}
|
||||
}
|
||||
return B().C().calc()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if (A().calc() == 6) "OK" else "fail"
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
fun String.bar(): String {
|
||||
open class Local {
|
||||
fun result() = this@bar
|
||||
}
|
||||
|
||||
class Outer {
|
||||
inner class Inner : Local() {
|
||||
fun outer() = this@Outer
|
||||
}
|
||||
}
|
||||
|
||||
return Outer().Inner().result()
|
||||
}
|
||||
|
||||
fun box() = "OK".bar()
|
||||
@@ -0,0 +1,17 @@
|
||||
package a.b
|
||||
|
||||
interface Test {
|
||||
fun invoke(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
private val a : Test = {
|
||||
object : Test {
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
fun box(): String {
|
||||
return a.invoke();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo() : String {
|
||||
val u = {
|
||||
class B(val data : String)
|
||||
B("OK").data
|
||||
}
|
||||
return u()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.example
|
||||
|
||||
interface SomeTrait {}
|
||||
|
||||
interface KotlinProcessor<T> {
|
||||
fun execute(callback: KotlinCallback<T>?);
|
||||
}
|
||||
|
||||
interface KotlinCallback<T> {
|
||||
fun on(t : T);
|
||||
}
|
||||
|
||||
public class Test(name : String) : KotlinProcessor<SomeTrait> {
|
||||
public override fun execute(callback: KotlinCallback<SomeTrait>?) {
|
||||
if(callback != null) {
|
||||
class InlineTrait : SomeTrait {}
|
||||
|
||||
var inlineTrait = InlineTrait()
|
||||
callback.on(inlineTrait)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var f = "fail"
|
||||
Test("OK").execute(object : KotlinCallback<SomeTrait> {
|
||||
override fun on(t: SomeTrait) {
|
||||
f = "OK"
|
||||
}
|
||||
})
|
||||
return f
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package t
|
||||
|
||||
class Reproduce {
|
||||
|
||||
fun test(): String {
|
||||
data class Foo(val bar: String, val baz: Int)
|
||||
val foo = Foo("OK", 5)
|
||||
return foo.bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return Reproduce().test()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fun box(): String {
|
||||
val s = "captured";
|
||||
|
||||
class A(val param: String = "OK") {
|
||||
val s2 = s + param
|
||||
}
|
||||
|
||||
if (A().s2 != "capturedOK") return "fail 1: ${A().s2}"
|
||||
|
||||
if (A("Test").s2 != "capturedTest") return "fail 2: ${A("Test").s2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
open class C(val s: String) {
|
||||
fun test(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
class B(var x: String) {
|
||||
fun foo(): String {
|
||||
var s = "OK"
|
||||
class Z : C(s) {}
|
||||
return Z().test()
|
||||
}
|
||||
|
||||
fun foo2(): String {
|
||||
class Y : C(x) {}
|
||||
return Y().test()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val b = B("OK")
|
||||
if (b.foo() != "OK") return "fail: ${b.foo()}"
|
||||
return b.foo2()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
fun a () : String {
|
||||
class B() {
|
||||
fun s() : String = "OK"
|
||||
}
|
||||
return B().s()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a()
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
class Outer {
|
||||
fun String.id(): String {
|
||||
class Local(unused: Long) {
|
||||
fun result() = this@id
|
||||
fun outer() = this@Outer
|
||||
}
|
||||
|
||||
return Local(42L).result()
|
||||
}
|
||||
|
||||
fun result(): String = "OK".id()
|
||||
}
|
||||
|
||||
fun box() = Outer().result()
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class A {
|
||||
var a: String = "Fail"
|
||||
|
||||
init {
|
||||
open class B() {
|
||||
open fun s() : String = "O"
|
||||
}
|
||||
|
||||
val o = object : B() {
|
||||
override fun s(): String = "K"
|
||||
}
|
||||
|
||||
a = B().s() + o.s()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return A().a
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class A(
|
||||
val a: String = {
|
||||
open class B() {
|
||||
open fun s() : String = "O"
|
||||
}
|
||||
|
||||
val o = object : B() {
|
||||
override fun s(): String = "K"
|
||||
}
|
||||
|
||||
B().s() + o.s()
|
||||
}()
|
||||
)
|
||||
|
||||
fun box() : String {
|
||||
return A().a
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fun box(): String {
|
||||
val capturedInConstructor = 1
|
||||
|
||||
data class A(var x: Int) {
|
||||
var y = 0
|
||||
|
||||
init {
|
||||
y += x + capturedInConstructor
|
||||
}
|
||||
}
|
||||
|
||||
val a = A(100).copy()
|
||||
if (a.y != 101) return "fail1a: ${a.y}"
|
||||
if (a.x != 100) return "fail1b: ${a.x}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
fun box(): String {
|
||||
class Local : Inner() {
|
||||
val u = foo()
|
||||
}
|
||||
val u = Local().u
|
||||
return if (u == 42) "OK" else "Fail $u"
|
||||
}
|
||||
|
||||
open inner class Inner
|
||||
fun foo() = 42
|
||||
}
|
||||
|
||||
fun box() = A().box()
|
||||
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
open class K {
|
||||
val o = "O"
|
||||
}
|
||||
|
||||
class Bar : K() {
|
||||
val k = "K"
|
||||
}
|
||||
|
||||
return K().o + Bar().k
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
val k = object {
|
||||
val ok = "OK"
|
||||
}
|
||||
|
||||
return k.ok
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class C() {
|
||||
val y = t
|
||||
|
||||
inner class D() {
|
||||
fun foo() = "($y;$t)"
|
||||
}
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = C()
|
||||
}
|
||||
|
||||
log += (s as C).D().foo()
|
||||
}
|
||||
|
||||
if (log != "(1;1)(1;1)(1;1)") return "fail: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val x = "OK"
|
||||
class Aaa {
|
||||
val y = x
|
||||
}
|
||||
|
||||
return Aaa().y
|
||||
}
|
||||
Reference in New Issue
Block a user