[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines
^KT-61259
This commit is contained in:
committed by
Space Team
parent
a1d13f54cb
commit
a5f3d5b737
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.array_to_any
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
foo().hashCode()
|
||||
}
|
||||
|
||||
fun foo(): Any {
|
||||
return Array<Any?>(0, { i -> null })
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.canonical_name
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I<U, T> {
|
||||
fun foo(a: U): T
|
||||
fun qux(a: T): U
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
class A1
|
||||
class A2
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
class A : I<A1, A2> {
|
||||
override fun foo(a: A1): A2 { println("A:foo"); return A2() }
|
||||
override fun qux(a: A2): A1 { println("A:qux"); return A1() }
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun <U, V> baz(i: I<U, V>, u: U, v:V) {
|
||||
i.foo(u)
|
||||
i.qux(v)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
baz<A1, A2>(A(), A1(), A2())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
A:foo
|
||||
A:qux
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.cast_null
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
testCast(null, false)
|
||||
testCastToNullable(null, true)
|
||||
testCastToNullable(TestKlass(), true)
|
||||
testCastToNullable("", false)
|
||||
testCastNotNullableToNullable(TestKlass(), true)
|
||||
testCastNotNullableToNullable("", false)
|
||||
|
||||
println("Ok")
|
||||
}
|
||||
|
||||
class TestKlass
|
||||
|
||||
fun ensure(b: Boolean) {
|
||||
if (!b) {
|
||||
println("Error")
|
||||
}
|
||||
}
|
||||
|
||||
fun testCast(x: Any?, expectSuccess: Boolean) {
|
||||
try {
|
||||
x as TestKlass
|
||||
} catch (e: Throwable) {
|
||||
ensure(!expectSuccess)
|
||||
return
|
||||
}
|
||||
ensure(expectSuccess)
|
||||
}
|
||||
|
||||
fun testCastToNullable(x: Any?, expectSuccess: Boolean) {
|
||||
try {
|
||||
x as TestKlass?
|
||||
} catch (e: Throwable) {
|
||||
ensure(!expectSuccess)
|
||||
return
|
||||
}
|
||||
ensure(expectSuccess)
|
||||
}
|
||||
|
||||
fun testCastNotNullableToNullable(x: Any, expectSuccess: Boolean) {
|
||||
try {
|
||||
x as TestKlass?
|
||||
} catch (e: Throwable) {
|
||||
ensure(!expectSuccess)
|
||||
return
|
||||
}
|
||||
ensure(expectSuccess)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.cast_simple
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A() {}
|
||||
class B(): A() {}
|
||||
|
||||
fun castSimple(o: Any) : A = o as A
|
||||
|
||||
fun castTest(): Boolean {
|
||||
val b = B()
|
||||
castSimple(b)
|
||||
return true
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
if (!castTest()) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.check_type
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I
|
||||
class A() : I {}
|
||||
class B() {}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isTypeOf(a: Any?) : Boolean {
|
||||
return a is A
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isTypeNullableOf(a: Any?) : Boolean {
|
||||
return a is A?
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isNotTypeOf(a: Any) : Boolean {
|
||||
return a !is A
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
fun isTypeOfInterface(a: Any) : Boolean {
|
||||
return a is I
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
println(isTypeOf(A()))
|
||||
println(isTypeOf(null))
|
||||
println(isTypeNullableOf(A()))
|
||||
println(isTypeNullableOf(null))
|
||||
println(isNotTypeOf(B()))
|
||||
println(isTypeOfInterface(A()))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
true
|
||||
false
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo() = "comp"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.concatenation
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val s = "world"
|
||||
val i = 1
|
||||
println("Hello $s $i ${2*i}")
|
||||
|
||||
for (item in listOf("a", "b")) {
|
||||
println("Hello, $item")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Hello world 1 2
|
||||
Hello, a
|
||||
Hello, b
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.const_infinity
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
//Original issue here https://youtrack.jetbrains.com/issue/KT-37212
|
||||
@Suppress("DIVISION_BY_ZERO")
|
||||
const val fpInfConst = 1.0F / 0.0F
|
||||
@Suppress("DIVISION_BY_ZERO")
|
||||
val fpInfVal = 1.0F / 0.0F
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertEquals(fpInfConst, Float.POSITIVE_INFINITY)
|
||||
assertEquals(fpInfVal, Float.POSITIVE_INFINITY)
|
||||
assertEquals(fpInfConst, fpInfVal)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.expression_as_statement
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo() {
|
||||
Any() as String
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Throwable) {
|
||||
println("Ok")
|
||||
return
|
||||
}
|
||||
|
||||
println("Fail")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,37 @@
|
||||
package codegen.basics.k42000_1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertTrue(Reproducer().repro() > 0)
|
||||
}
|
||||
|
||||
// Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0
|
||||
|
||||
val Int.isEven get() = this % 2 == 0
|
||||
|
||||
inline operator fun <reified T : Number> T.plus(other: T): T = when (T::class) {
|
||||
Double::class -> (this as Double) + (other as Double)
|
||||
Int::class -> (this as Int) + (other as Int)
|
||||
Long::class -> (this as Long) + (other as Long)
|
||||
else -> TODO()
|
||||
} as T
|
||||
|
||||
inline fun <reified T : Number> Collection<T>.median(): Double {
|
||||
val sorted = this.sortedBy {
|
||||
it.toDouble()
|
||||
}
|
||||
|
||||
return if (size.isEven || size == 1) {
|
||||
sorted[size / 2]
|
||||
} else {
|
||||
sorted[size / 2] + sorted[size / 2 + 1]
|
||||
}.toDouble()
|
||||
}
|
||||
|
||||
class Reproducer {
|
||||
private var someListOfLongs = mutableListOf<Long>(1L)
|
||||
|
||||
fun repro() = someListOfLongs.median()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package codegen.basics.k42000_2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-42000
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertFailsWith<Error> {
|
||||
when (1) {
|
||||
else -> throw Error()
|
||||
} as String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.local_variable
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun local_variable(a: Int) : Int {
|
||||
var b = 0
|
||||
b = a + 11
|
||||
return b
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
if (local_variable(3) != 14) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.null_check
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
//--- Test "eqeq" -------------------------------------------------------------//
|
||||
|
||||
fun check_eqeq(a: Any?) = a == null
|
||||
|
||||
fun null_check_eqeq1() : Boolean {
|
||||
return check_eqeq(Any())
|
||||
}
|
||||
|
||||
fun null_check_eqeq2() : Boolean {
|
||||
return check_eqeq(null)
|
||||
}
|
||||
|
||||
//--- Test "eqeqeq" -----------------------------------------------------------//
|
||||
|
||||
fun check_eqeqeq(a: Any?) = a === null
|
||||
|
||||
fun null_check_eqeqeq1() : Boolean {
|
||||
return check_eqeqeq(Any())
|
||||
}
|
||||
|
||||
fun null_check_eqeqeq2() : Boolean {
|
||||
return check_eqeqeq(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
if (null_check_eqeq1()) throw Error()
|
||||
if (!null_check_eqeq2()) throw Error()
|
||||
if (null_check_eqeqeq1()) throw Error()
|
||||
if (!null_check_eqeqeq2()) throw Error()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.safe_cast
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A
|
||||
class B : A()
|
||||
class C
|
||||
|
||||
fun foo(a: Any) : A? = a as? A
|
||||
|
||||
fun safe_cast_positive(): Boolean {
|
||||
val b = B()
|
||||
return foo(b) === b
|
||||
}
|
||||
|
||||
fun safe_cast_negative(): Boolean {
|
||||
val c = C()
|
||||
return foo(c) == null
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val safeCastPositive = safe_cast_positive().toString()
|
||||
val safeCastNegative = safe_cast_negative().toString()
|
||||
println("safe_cast_positive: " + safeCastPositive)
|
||||
println("safe_cast_negative: " + safeCastNegative)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
safe_cast_positive: true
|
||||
safe_cast_negative: true
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.spread_operator_0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val list0 = _arrayOf("K", "o", "t", "l", "i", "n")
|
||||
val list1 = _arrayOf("l", "a","n", "g", "u", "a", "g", "e")
|
||||
val list = foo(list0, list1)
|
||||
println(list.toString())
|
||||
}
|
||||
|
||||
|
||||
fun foo(a:Array<out String>, b:Array<out String>) = listOf(*a," ", "i", "s", " ", "c", "o", "o", "l", " ", *b)
|
||||
|
||||
|
||||
fun _arrayOf(vararg arg:String) = arg
|
||||
@@ -0,0 +1 @@
|
||||
[K, o, t, l, i, n, , i, s, , c, o, o, l, , l, a, n, g, u, a, g, e]
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.superFunCall
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class C {
|
||||
open fun f() = "<fun:C>"
|
||||
}
|
||||
|
||||
class C1: C() {
|
||||
override fun f() = super<C>.f() + "<fun:C1>"
|
||||
}
|
||||
|
||||
open class C2: C() {
|
||||
}
|
||||
|
||||
class C3: C2() {
|
||||
override fun f() = super<C2>.f() + "<fun:C3>"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
println(C1().f())
|
||||
println(C3().f())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<fun:C><fun:C1>
|
||||
<fun:C><fun:C3>
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.superGetterCall
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class C {
|
||||
open val p1 = "<prop:C>"
|
||||
}
|
||||
|
||||
class C1: C() {
|
||||
override val p1 = super<C>.p1 + "<prop:C1>"
|
||||
}
|
||||
|
||||
open class C2: C() {
|
||||
}
|
||||
|
||||
class C3: C2() {
|
||||
override val p1 = super<C2>.p1 + "<prop:C3>"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
println(C1().p1)
|
||||
println(C3().p1)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<prop:C><prop:C1>
|
||||
<prop:C><prop:C3>
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.superSetterCall
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class C {
|
||||
open var p2 = "<prop:C>"
|
||||
set(value) { field = "<prop:C>" + value }
|
||||
}
|
||||
|
||||
class C1: C() {
|
||||
override var p2 = super<C>.p2 + "<prop:C1>"
|
||||
set(value) {
|
||||
super<C>.p2 = value
|
||||
field = "<prop:C1>" + super<C>.p2
|
||||
}
|
||||
}
|
||||
|
||||
open class C2: C() {
|
||||
}
|
||||
|
||||
class C3: C2() {
|
||||
override var p2 = super<C2>.p2 + "<prop:C3>"
|
||||
set(value) {
|
||||
super<C2>.p2 = value
|
||||
field = "<prop:C3>" + super<C2>.p2
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val c1 = C1()
|
||||
val c3 = C3()
|
||||
c1.p2 = "zzz"
|
||||
c3.p2 = "zzz"
|
||||
println(c1.p2)
|
||||
println(c3.p2)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<prop:C1><prop:C>zzz
|
||||
<prop:C3><prop:C>zzz
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.typealias1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
println(Bar(42).x)
|
||||
}
|
||||
|
||||
class Foo(val x: Int)
|
||||
typealias Bar = Foo
|
||||
@@ -0,0 +1 @@
|
||||
42
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unchecked_cast1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
foo<String>("17")
|
||||
bar<String>("17")
|
||||
foo<String>(42)
|
||||
bar<String>(42)
|
||||
}
|
||||
|
||||
fun <T> foo(x: Any?) {
|
||||
val y = x as T
|
||||
println(y.toString())
|
||||
}
|
||||
|
||||
fun <T> bar(x: Any?) {
|
||||
val y = x as? T
|
||||
println(y.toString())
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
17
|
||||
17
|
||||
42
|
||||
42
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unchecked_cast2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
try {
|
||||
val x = cast<String>(Any())
|
||||
println(x.length)
|
||||
} catch (e: Throwable) {
|
||||
println("Ok")
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> cast(x: Any?) = x as T
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unchecked_cast3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
testCast<TestKlass>(TestKlass(), true)
|
||||
testCast<TestKlass>(null, false)
|
||||
testCastToNullable<TestKlass>(null, true)
|
||||
|
||||
println("Ok")
|
||||
}
|
||||
|
||||
class TestKlass
|
||||
|
||||
fun ensure(b: Boolean) {
|
||||
if (!b) {
|
||||
println("Error")
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Any> testCast(x: Any?, expectSuccess: Boolean) {
|
||||
try {
|
||||
x as T
|
||||
} catch (e: Throwable) {
|
||||
ensure(!expectSuccess)
|
||||
return
|
||||
}
|
||||
ensure(expectSuccess)
|
||||
}
|
||||
|
||||
fun <T : Any> testCastToNullable(x: Any?, expectSuccess: Boolean) {
|
||||
try {
|
||||
x as T?
|
||||
} catch (e: Throwable) {
|
||||
ensure(!expectSuccess)
|
||||
return
|
||||
}
|
||||
ensure(expectSuccess)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unchecked_cast4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
CI1I2().uncheckedCast<CI1I2>()
|
||||
CI1I2().uncheckedCast<OtherCI1I2>()
|
||||
|
||||
assertFailsWith<ClassCastException> {
|
||||
Any().uncheckedCast<CI1I2>()
|
||||
}
|
||||
|
||||
println("Ok")
|
||||
}
|
||||
|
||||
fun <R : C> Any?.uncheckedCast() where R : I1, R : I2 {
|
||||
this as R
|
||||
}
|
||||
|
||||
interface I1
|
||||
interface I2
|
||||
open class C
|
||||
|
||||
class CI1I2 : C(), I1, I2
|
||||
class OtherCI1I2 : C(), I1, I2
|
||||
@@ -0,0 +1 @@
|
||||
Ok
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unit1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
println(println("First").toString())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
First
|
||||
kotlin.Unit
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unit2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
val x = foo()
|
||||
println(x.toString())
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
return Unit
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.Unit
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unit3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
foo(Unit)
|
||||
}
|
||||
|
||||
fun foo(x: Any) {
|
||||
println(x.toString())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.Unit
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.basics.unit4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
for (x in 0 .. 8) {
|
||||
foo(x, Unit)
|
||||
}
|
||||
println("Done")
|
||||
}
|
||||
|
||||
var global = 42
|
||||
|
||||
fun foo(x: Int, unit: Unit) {
|
||||
var local = 5
|
||||
val y: Unit = when (x) {
|
||||
0 -> {}
|
||||
1 -> local = 6
|
||||
2 -> global = 43
|
||||
3 -> unit
|
||||
4 -> Unit
|
||||
5 -> bar()
|
||||
6 -> return
|
||||
7 -> {
|
||||
5
|
||||
bar()
|
||||
}
|
||||
8 -> {
|
||||
val z: Any = Unit
|
||||
z as Unit
|
||||
}
|
||||
else -> throw Error()
|
||||
}
|
||||
|
||||
if (y !== Unit) {
|
||||
println("Fail at x = $x")
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Done
|
||||
Reference in New Issue
Block a user