Remove some legacy codegen tests, move some to generated
This commit is contained in:
committed by
Alexander Udalov
parent
f8dfaf4599
commit
bab127ad33
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A {
|
||||
fun f(): () -> String {
|
||||
val s = "OK"
|
||||
return { -> s }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val lambdaClass = A().f().javaClass
|
||||
val fields = lambdaClass.getDeclaredFields().toList()
|
||||
if (fields.size != 1) return "Fail: lambda should only capture 's': $fields"
|
||||
|
||||
val fieldName = fields[0].getName()
|
||||
if (fieldName != "\$s") return "Fail: captured variable should be named '\$s': $fields"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
fun continue_test(i: Int): Int {
|
||||
fun foo(i: Int): Int {
|
||||
var count = i;
|
||||
var result = 0;
|
||||
while(count > 0) {
|
||||
@@ -8,3 +8,9 @@ fun continue_test(i: Int): Int {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (foo(4) != 3) return "Fail 1"
|
||||
if (foo(5) != 7) return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun facWhile(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
while(count < i) {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fun facBreak(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
while(true) {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
if (count == i) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fun facDoWhile(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
do {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
} while(count != i);
|
||||
return result;
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, facWhile(3))
|
||||
assertEquals(6, facBreak(3))
|
||||
assertEquals(6, facDoWhile(3))
|
||||
assertEquals(120, facWhile(5))
|
||||
assertEquals(120, facBreak(5))
|
||||
assertEquals(120, facDoWhile(5))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
interface IActing {
|
||||
fun act(): String
|
||||
}
|
||||
|
||||
class CActing(val value: String = "OK") : IActing {
|
||||
override fun act(): String = value
|
||||
}
|
||||
|
||||
// final so no need in delegate field
|
||||
class Test(val acting: CActing = CActing()) : IActing by acting {
|
||||
}
|
||||
|
||||
// even if open so we don't need delegate field
|
||||
open class Test2(open val acting: CActing = CActing()) : IActing by acting {
|
||||
}
|
||||
|
||||
// even if open the backing field is final, so we don't need delegate field
|
||||
class Test3() : Test2() {
|
||||
override val acting = CActing("OKOK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
Test::class.java.getDeclaredField("\$delegate_0")
|
||||
return "\$delegate_0 field generated for class Test but should not"
|
||||
}
|
||||
catch (e: NoSuchFieldException) {
|
||||
// ok
|
||||
}
|
||||
|
||||
try {
|
||||
Test2::class.java.getDeclaredField("\$delegate_0")
|
||||
return "\$delegate_0 field generated for class Test but should not"
|
||||
}
|
||||
catch (e: NoSuchFieldException) {
|
||||
// ok
|
||||
}
|
||||
|
||||
if (Test3().acting.act() != "OKOK") return "Fail Test3"
|
||||
|
||||
val test = Test()
|
||||
return test.act()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class IssueState {
|
||||
DEFAULT,
|
||||
FIXED {
|
||||
override fun ToString() = "K"
|
||||
};
|
||||
|
||||
open fun ToString(): String = "O"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val field = IssueState::class.java.getField("FIXED")
|
||||
|
||||
val typeName = field.type.name
|
||||
if (typeName != "IssueState") return "Fail type name: $typeName"
|
||||
|
||||
val className = field.get(null).javaClass.name
|
||||
if (className != "IssueState\$FIXED") return "Fail class name: $className"
|
||||
|
||||
val classLoader = IssueState::class.java.classLoader
|
||||
classLoader.loadClass("IssueState\$FIXED")
|
||||
try {
|
||||
classLoader.loadClass("IssueState\$DEFAULT")
|
||||
return "Fail: no class should have been generated for DEFAULT"
|
||||
}
|
||||
catch (e: Exception) {
|
||||
// ok
|
||||
}
|
||||
|
||||
return IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
enum class En {
|
||||
Y
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val klass = En::class.java
|
||||
val superclass = klass.superclass.name
|
||||
if (superclass != "java.lang.Enum") "Fail superclass: $superclass"
|
||||
|
||||
val enumModifiers = klass.modifiers
|
||||
if ((enumModifiers and 0x4000) == 0) return "Fail ACC_ENUM on class"
|
||||
if ((enumModifiers and Modifier.FINAL) == 0) return "Fail FINAL on class"
|
||||
|
||||
val entry = klass.getField("Y")
|
||||
val entryModifiers = entry.modifiers
|
||||
if ((entryModifiers and 0x4000) == 0) return "Fail ACC_ENUM on entry"
|
||||
if ((entryModifiers and Modifier.FINAL) == 0) return "Fail FINAL on entry"
|
||||
if ((entryModifiers and Modifier.STATIC) == 0) return "Fail FINAL on entry"
|
||||
if ((entryModifiers and Modifier.PUBLIC) == 0) return "Fail FINAL on entry"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
enum class State {
|
||||
O,
|
||||
K
|
||||
}
|
||||
|
||||
fun box() = "${State.O.name}${State.K.name}"
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class State {
|
||||
O,
|
||||
K
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val field = State::class.java.getField("O")
|
||||
val className = field.get(null).javaClass.name
|
||||
if (className != "State") return "Fail: $className"
|
||||
|
||||
return "${State.O.name}${State.K.name}"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString()
|
||||
|
||||
enum class IssueState {
|
||||
DEFAULT,
|
||||
FIXED {
|
||||
override fun ToString() = "K"
|
||||
};
|
||||
|
||||
open fun ToString() : String = "O"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class N {
|
||||
fun foo() = null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val method = N::class.java.getDeclaredMethod("foo")
|
||||
if (method.returnType.name != "java.lang.Void") return "Fail: Nothing should be mapped to Void"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun isZero(x: Int) = when(x) {
|
||||
0 -> true
|
||||
else -> throw Exception()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
isZero(1)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
return "OK"
|
||||
}
|
||||
return "Fail"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo(x: Any) =
|
||||
when (x) {
|
||||
0, 1 -> "bit"
|
||||
else -> "something"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (foo(0) != "bit") return "Fail 0"
|
||||
if (foo(1) != "bit") return "Fail 1"
|
||||
if (foo(2) != "something") return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(x: String, y: Any?) = x + y + 120
|
||||
|
||||
// 0 stringPlus
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(x: String?, y: Any?) = x + y
|
||||
|
||||
// 1 stringPlus
|
||||
@@ -1,9 +0,0 @@
|
||||
class C() {
|
||||
fun getInstance(): Runnable = C
|
||||
|
||||
companion object: Runnable {
|
||||
override fun run(): Unit { }
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() = C().getInstance()
|
||||
@@ -1,3 +0,0 @@
|
||||
class A {
|
||||
companion object
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
interface IActing {
|
||||
fun act(): String
|
||||
}
|
||||
|
||||
class CActing(val value: String = "OK"): IActing {
|
||||
override fun act(): String = value
|
||||
}
|
||||
|
||||
// final so no need in delegate field
|
||||
class Test(val acting: CActing = CActing()): IActing by acting {
|
||||
}
|
||||
|
||||
// even if open so we don't need delegate field
|
||||
open class Test2(open val acting: CActing = CActing()): IActing by acting {
|
||||
}
|
||||
|
||||
// even if open the backing field is final, so we don't need delegate field
|
||||
class Test3() : Test2() {
|
||||
override val acting = CActing("OKOK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test()
|
||||
return test.act()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
class Foo() : java.util.ArrayList<Int>()
|
||||
@@ -1,8 +0,0 @@
|
||||
class SimpleClass() {
|
||||
fun foo() = 610
|
||||
}
|
||||
|
||||
fun test() : Int {
|
||||
val c = SimpleClass()
|
||||
return c.foo()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class SimpleClass {
|
||||
fun foo() : Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fun fac(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
while(true) {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
if (count == i) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun fac(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
do {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
} while(count != i);
|
||||
return result;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
fun concat(l: List<String>): String? {
|
||||
val sb = StringBuilder()
|
||||
for(s in l) {
|
||||
sb.append(s)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun concat(l: Array<String>): String? {
|
||||
val sb = StringBuilder()
|
||||
for(s in l) {
|
||||
sb.append(s)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
fun foo(b: Boolean): Int { return if (b) 15 else 20 }
|
||||
@@ -1,10 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
fun concat(l: List<String>): String? {
|
||||
val sb = StringBuilder()
|
||||
for(s in l) {
|
||||
val x = if(l.size > 1) { "T" } else { "F" };
|
||||
sb.append(x)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
fun f(x: Int, b: Boolean): Int {
|
||||
var result = x;
|
||||
if (b) else result = result + 5;
|
||||
return result;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun foo(b: Boolean) : Int {
|
||||
if (b) return 15;
|
||||
return 20;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun foo(s: String): String? {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
return "no message";
|
||||
}
|
||||
catch(e: NumberFormatException) {
|
||||
return e.message // Work around an overload-resolution bug
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun f(sb: StringBuilder, s: String): Unit {
|
||||
try {
|
||||
sb.append("foo");
|
||||
sb.append(Integer.parseInt(s));
|
||||
}
|
||||
finally {
|
||||
sb.append("bar");
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun fac(i: Int): Int {
|
||||
var count = 1;
|
||||
var result = 1;
|
||||
while(count < i) {
|
||||
count = count + 1;
|
||||
result = result * count;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
enum class State {
|
||||
O,
|
||||
K
|
||||
}
|
||||
|
||||
fun box() = "${State.O.name}${State.K.name}"
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString()
|
||||
|
||||
enum class IssueState {
|
||||
DEFAULT,
|
||||
FIXED {
|
||||
override fun ToString() = "K"
|
||||
};
|
||||
|
||||
open fun ToString() : String = "O"
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
enum class Season {
|
||||
WINTER,
|
||||
SPRING,
|
||||
SUMMER,
|
||||
AUTUMN
|
||||
}
|
||||
|
||||
fun foo(): Season = Season.SPRING
|
||||
|
||||
fun box() =
|
||||
if (foo() == Season.SPRING) "OK"
|
||||
else "fail"
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
import org.junit.Test
|
||||
|
||||
@Test fun foo(m : java.lang.reflect.Method) = "OK"
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
public class Test {
|
||||
@test fun f(): Unit {
|
||||
assertEquals(true, !false)
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
Test().f()
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun isZero(x: Int) = when(x) {
|
||||
0 -> true
|
||||
else -> false
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun isZero(x: Int) = when(x) {
|
||||
0 -> true
|
||||
else -> throw Exception()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fun isDigit(a: Int) : String {
|
||||
val aa = java.util.ArrayList<Int> ()
|
||||
aa.add(239)
|
||||
|
||||
if(a in aa) return "array list"
|
||||
if(a in 0..9) return "digit"
|
||||
if(a !in 0..100) return "not small"
|
||||
return "something"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun isString(x: Any) = when(x) {
|
||||
is String -> "string"
|
||||
else -> "something"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
fun isDigit(a: Char) = when(a) {
|
||||
in '0'..'9' -> "digit"
|
||||
else -> "something"
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package interactive
|
||||
|
||||
class Shape(var height : Double = 1.0, var fillColor : String = "#AAAAAA") {
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var a : Shape? = Shape()
|
||||
a?.height = 1.0
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
// KT-297 Overload resolution ambiguity with required in interface
|
||||
interface ALE<T> : java.util.ArrayList<T> {
|
||||
fun getOrValue(index: Int, value : T) : T = if(index >= 0 && index < size) get(index) else value
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package kt799
|
||||
|
||||
fun foo(b: Boolean) : String {
|
||||
val a = if (b) true else return "false"
|
||||
return "$a"
|
||||
}
|
||||
|
||||
fun box() = if (foo(true) == "true" && foo(false) == "false") "OK" else "fail"
|
||||
Reference in New Issue
Block a user