Fix tests: "Placing function type parameters after the function name" error

This commit is contained in:
Yan Zhulanow
2015-11-26 15:56:31 +03:00
parent 3001af56c9
commit a3ff3ffc45
435 changed files with 550 additions and 569 deletions
+2 -2
View File
@@ -4,14 +4,14 @@ package kotlin
fun fail(message: String? = null): Nothing = throw Exception(message)
fun assertEquals<T>(expected: T, actual: T, message: String? = null) {
fun <T> assertEquals(expected: T, actual: T, message: String? = null) {
if (expected != actual) {
val msg = if (message == null) "" else (" message = '" + message + "',")
fail("Unexpected value:$msg expected = '$expected', actual = '$actual'")
}
}
fun assertNotEquals<T>(illegal: T, actual: T, message: String? = null) {
fun <T> assertNotEquals(illegal: T, actual: T, message: String? = null) {
if (illegal == actual) {
val msg = if (message == null) "" else (" message = '" + message + "',")
fail("Illegal value:$msg illegal = '$illegal', actual = '$actual'")
+1 -1
View File
@@ -1,7 +1,7 @@
package java.util
public object Arrays {
public fun asList<T>(vararg ts : T) : List<T> {
public fun <T> asList(vararg ts : T) : List<T> {
val result = ArrayList<T>()
for (t in ts) {
result.add(t)
+1 -1
View File
@@ -1,3 +1,3 @@
package foo
fun myRun<T>(f: () -> T) = f()
fun <T> myRun(f: () -> T) = f()
@@ -8,7 +8,7 @@ class A {
class B
fun with<T>(o: T, body: T.() -> Unit) {
fun <T> with(o: T, body: T.() -> Unit) {
o.body()
}
+2 -2
View File
@@ -9,7 +9,7 @@ data class Dat(val start: String, val end: String)
class Obj(val start: String, val end: String)
fun assertSomeNotEqual<T>(c: Iterable<T>) {
fun <T> assertSomeNotEqual(c: Iterable<T>) {
val it = c.iterator()
val first = it.next()
while (it.hasNext()) {
@@ -21,7 +21,7 @@ fun assertSomeNotEqual<T>(c: Iterable<T>) {
throw Exception("All elements are the same: $first")
}
fun assertAllEqual<T>(c: Iterable<out T>) {
fun <T> assertAllEqual(c: Iterable<out T>) {
val it = c.iterator()
val first = it.next()
while (it.hasNext()) {
@@ -1,7 +1,7 @@
// KT-6037: KT-6037 Javascript default function arguments fill code generated in wrong order on method without "return keyword"
package foo
inline fun id<T>(x: T) = x
inline fun <T> id(x: T) = x
fun test(arg: Int = 10) = id(arg)
@@ -3,9 +3,9 @@ class Foo() {
class Bar() {
}
fun isInstance<T>(obj: Any?) = obj is T
fun <T> isInstance(obj: Any?) = obj is T
fun isInstance2<T>(obj: Any?) = isInstance<T>(obj)
fun <T> isInstance2(obj: Any?) = isInstance<T>(obj)
fun box(): String {
if (!isInstance2<Foo>(Foo())) return "fail 1"
@@ -2,14 +2,14 @@ package foo
class A(val s: String)
fun castsNotNullToNullableT<T>(a: Any) {
fun <T> castsNotNullToNullableT(a: Any) {
a as T
a as T?
a as? T
a as? T?
}
fun castsNullableToNullableT<T>(a: Any?) {
fun <T> castsNullableToNullableT(a: Any?) {
a as T
a as T?
a as? T
@@ -17,18 +17,18 @@ fun castsNullableToNullableT<T>(a: Any?) {
}
fun castsNotNullToNotNullT<T : Any>(a: Any) {
fun <T : Any> castsNotNullToNotNullT(a: Any) {
a as T
a as T?
a as? T
a as? T?
}
fun castNullableToNotNullT<T : Any>(a: Any?) {
fun <T : Any> castNullableToNotNullT(a: Any?) {
a as T
}
fun castsNullableToNotNullT<T : Any>(a: Any?) {
fun <T : Any> castsNullableToNotNullT(a: Any?) {
a as T?
a as? T
a as? T?
@@ -2,16 +2,16 @@ package foo
var global: String = ""
fun bar<T>(s: String, value: T): T {
fun <T> bar(s: String, value: T): T {
global += s
return value
}
fun baz<T>(vararg args: T): String {
fun <T> baz(vararg args: T): String {
return "baz: ${args.size()}"
}
fun idVarArg<T>(vararg a: T) = a
fun <T> idVarArg(vararg a: T) = a
fun box(): String {
baz(bar("A", 10), try { global += "B"; 20} finally {})
@@ -8,9 +8,9 @@ fun Int.foo2(): (i: Int) -> Int {
return { x -> x + this }
}
fun fooT1<T>(t: T) = { t.toString() }
fun <T> fooT1(t: T) = { t.toString() }
fun fooT2<T>(t: T) = { x: T -> t.toString() + x.toString() }
fun <T> fooT2(t: T) = { x: T -> t.toString() + x.toString() }
fun box(): Any? {
if ( (10.foo1())() != "23910") return "foo1 fail"
@@ -34,9 +34,9 @@ fun spreadInObjectMethodCall(size: Int, sum: Int, vararg args: Int) = obj.test(s
fun testVarargWithFunLit(vararg args: Int, f: (a: IntArray) -> Boolean): Boolean = f(args)
fun idVarArgs<T>(vararg a: T) = a
fun <T> idVarArgs(vararg a: T) = a
fun idArrayVarArg<T>(vararg a: Array<T>) = a
fun <T> idArrayVarArg(vararg a: Array<T>) = a
fun sumFunValuesOnParameters(x: Int, y: Int, vararg a: Int, f: (Int) -> Int): Int {
var result = f(x) + f(y)
@@ -5,7 +5,7 @@ package foo
// A copy of stdlib run function.
// Copied to not to depend on run implementation.
// It's important, that the body is just `return fn()`.
internal inline fun evaluate<T>(fn: ()->T): T = fn()
internal inline fun <T> evaluate(fn: ()->T): T = fn()
internal fun test(n: Int): Int {
return evaluate {
+1 -1
View File
@@ -4,7 +4,7 @@ package foo
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=multiplyBy2$f_0
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=run
internal inline fun runLambdaInLambda<T>(noinline inner: (T) -> T, outer: ((T) -> T, T) -> T, arg: T): T {
internal inline fun <T> runLambdaInLambda(noinline inner: (T) -> T, outer: ((T) -> T, T) -> T, arg: T): T {
return outer(inner, arg)
}
@@ -12,27 +12,27 @@ package foo
// CHECK_HAS_NO_INLINE_METADATA: applyO_hiyix$
inline
public fun apply<T>(arg: T, func: (T)->T): T = func(arg)
public fun <T> apply(arg: T, func: (T)->T): T = func(arg)
public open class L {
inline
protected fun applyL<T>(arg: T, func: (T)->T): T = func(arg)
protected fun <T> applyL(arg: T, func: (T)->T): T = func(arg)
}
public class M {
inline
public fun applyM<T>(arg: T, func: (T)->T): T = func(arg)
public fun <T> applyM(arg: T, func: (T)->T): T = func(arg)
}
internal class N {
inline
public fun applyN<T>(arg: T, func: (T)->T): T = func(arg)
public fun <T> applyN(arg: T, func: (T)->T): T = func(arg)
}
private object O {
public object OInner {
inline
public fun applyO<T>(arg: T, func: (T)->T): T = func(arg)
public fun <T> applyO(arg: T, func: (T)->T): T = func(arg)
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ package foo
// CHECK_CALLED_IN_SCOPE: scope=multiplyBy2 function=multiplyBy2$f
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=run
internal inline fun run<T>(noinline func: (T) -> T, arg: T): T {
internal inline fun <T> run(noinline func: (T) -> T, arg: T): T {
return func(arg)
}
@@ -14,13 +14,13 @@ fun pullLog(): String {
return string
}
fun fizz<T>(x: T): T {
fun <T> fizz(x: T): T {
log("fizz($x)")
return x
}
inline
fun buzz<T>(x: T): T {
fun <T> buzz(x: T): T {
log("buzz($x)")
return x
}
@@ -7,7 +7,7 @@ class MyList<T>(vararg val data: T) : AbstractList<T>() {
override val size: Int get() = data.size()
}
fun test<T>(expected: String, list: List<T>) {
fun <T> test(expected: String, list: List<T>) {
var s = ""
for (e in list) {
s += "$e,"
+1 -1
View File
@@ -2,7 +2,7 @@ package foo
import java.util.ArrayList;
fun test<T>(list: List<T>, elements: List<T>, expected: List<Int>, method: List<T>.(T) -> Int, methodName: String): String? {
fun <T> test(list: List<T>, elements: List<T>, expected: List<Int>, method: List<T>.(T) -> Int, methodName: String): String? {
for (i in 0..elements.size() - 1) {
val actual = list.method(elements[i])
if (actual != expected[i]) return "$methodName failed when find: ${elements[i]}, expected: ${expected[i]}, actual: $actual"
@@ -3,7 +3,7 @@ package foo
import java.util.ArrayList;
fun test<T>(a: List<T>, b: List<T>, removed: Boolean, expected: List<T>): String? {
fun <T> test(a: List<T>, b: List<T>, removed: Boolean, expected: List<T>): String? {
val t = ArrayList<T>(a.size())
t.addAll(a)
@@ -2,7 +2,7 @@ package foo
import java.util.ArrayList;
fun test<T>(a: List<T>, b: List<T>, removed: Boolean, expected: List<T>): String? {
fun <T> test(a: List<T>, b: List<T>, removed: Boolean, expected: List<T>): String? {
val t = ArrayList<T>(a.size)
t.addAll(a)
+1 -1
View File
@@ -1,6 +1,6 @@
package foo
fun run<A, B, C>(a: A, b: B, func: (A, B) -> C): C = js("func(a, b)")
fun <A, B, C> run(a: A, b: B, func: (A, B) -> C): C = js("func(a, b)")
fun box(): String {
assertEquals(3, run(1, 2) { a, b -> a + b})
+1 -1
View File
@@ -4,7 +4,7 @@ package foo
val name: String
}
fun assertArrayEquals<T>(expected: Array<T>, actual: Array<T>) {
fun <T> assertArrayEquals(expected: Array<T>, actual: Array<T>) {
val expectedSize = expected.size()
val actualSize = actual.size()
@@ -5,7 +5,7 @@
package foo
fun myRun<R>(f: () -> R) = f()
fun <R> myRun(f: () -> R) = f()
fun test0() {
val a = aa@ 1
@@ -23,7 +23,7 @@ class AnotherClass : Trait {
override fun baz(): String = "AnotherClass().boo()"
}
fun test<T : NativeTrait>(c: T, className: String) {
fun <T : NativeTrait> test(c: T, className: String) {
assertEquals("$className().foo", c.foo)
assertEquals("$className().bar(3)", c.bar(3))
assertEquals("$className().boo()", c.baz())
+2 -2
View File
@@ -7,7 +7,7 @@ fun paramCount(vararg a: Int): Int = noImpl
fun anotherParamCount(vararg a: Int): Int = noImpl
@native("paramCount")
fun genericParamCount<T>(vararg a: T): Int = noImpl
fun <T> genericParamCount(vararg a: T): Int = noImpl
// test spread operator
fun count(vararg a: Int) = paramCount(*a)
@@ -66,7 +66,7 @@ fun sumOfParameters(x: Int, y: Int, vararg a: Int): Int = noImpl
fun sumFunValuesOnParameters(x: Int, y: Int, vararg a: Int, f: (Int) -> Int): Int = noImpl
@native
fun idArrayVarArg<T>(vararg a: Array<T>): Array<T> = noImpl
fun <T> idArrayVarArg(vararg a: Array<T>): Array<T> = noImpl
fun box(): String {
if (paramCount() != 0)
@@ -4,7 +4,7 @@ package foo
fun <T> _enumerate(o: T): T = noImpl
@native
fun _findFirst<T>(o: Any): T = noImpl
fun <T> _findFirst(o: Any): T = noImpl
class Test() {
val a: Int = 100
+2 -2
View File
@@ -6,9 +6,9 @@ package foo
class A
class B
inline fun test<reified T>(x: Any): Boolean = test1<T>(x)
inline fun <reified T> test(x: Any): Boolean = test1<T>(x)
inline fun test1<reified R>(x: Any): Boolean = x is R
inline fun <reified R> test1(x: Any): Boolean = x is R
fun box(): String {
assertEquals(true, test<A>(A()), "test<A>(A())")
+1 -1
View File
@@ -6,7 +6,7 @@ open class A
class B
class C : A()
inline fun Any.canBeCastedTo<reified T>(): Boolean = this is T
inline fun <reified T> Any.canBeCastedTo(): Boolean = this is T
fun box(): String {
assertEquals(true, A().canBeCastedTo<A>(), "A().canBeCastedTo<A>()")
+2 -2
View File
@@ -3,9 +3,9 @@ package foo
class A
class B
fun apply<T, R>(x: T, fn: T.()->R): R = x.fn()
fun <T, R> apply(x: T, fn: T.()->R): R = x.fn()
inline fun test<reified T, reified R>(x: Any, y: Any): Boolean =
inline fun <reified T, reified R> test(x: Any, y: Any): Boolean =
x is T && apply(y) { this is R }
fun box(): String {
+2 -4
View File
@@ -4,11 +4,9 @@ package foo
// CHECK_NOT_CALLED: fn
class A(val x: Any? = null) {
inline
fun test<reified T, reified R>(b: B) = b.fn<T, R>()
inline fun <reified T, reified R> test(b: B) = b.fn<T, R>()
inline
fun B.fn<reified T, reified R>() = x is T && y is R
inline fun <reified T, reified R> B.fn() = x is T && y is R
}
class B(val y: Any? = null)
+2 -2
View File
@@ -9,10 +9,10 @@ class B
class C : A()
interface TypePredicate {
fun invoke(x: Any): Boolean
operator fun invoke(x: Any): Boolean
}
inline fun typePredicate<reified T>(): TypePredicate =
inline fun <reified T> typePredicate(): TypePredicate =
object : TypePredicate {
override fun invoke(x: Any): Boolean = x is T
}
+1 -1
View File
@@ -25,7 +25,7 @@ fun <T> Array<T>.doFilter(fn: (T)->Boolean): List<T> {
return filtered
}
inline fun<reified T> filterIsInstance(arrayOfAnys: Array<Any>): List<T> {
inline fun <reified T> filterIsInstance(arrayOfAnys: Array<Any>): List<T> {
return arrayOfAnys.doFilter { it is T }.map { it as T }
}
+2 -2
View File
@@ -6,9 +6,9 @@ package foo
class X
class Y
fun doRun<R>(fn: ()->R): R = fn()
fun <R> doRun(fn: ()->R): R = fn()
inline fun test<reified A, reified B>(x: Any, y: Any): Boolean =
inline fun <reified A, reified B> test(x: Any, y: Any): Boolean =
doRun {
val isA = null
x is A
+1 -2
View File
@@ -3,8 +3,7 @@ package foo
// CHECK_NOT_CALLED: test
class A(val x: Any? = null) {
inline
fun test<reified T>() = x is T
inline fun <reified T> test() = x is T
}
class B
@@ -4,7 +4,7 @@ class X
class Y
class Z
inline fun test<reified A, B, reified C>(x: Any): String =
inline fun <reified A, B, reified C> test(x: Any): String =
when (x) {
is A -> "A"
is C -> "C"
@@ -4,7 +4,7 @@ package foo
class A
inline fun test<reified T>(): String {
inline fun <reified T> test(): String {
val a: Any = A()
return if (a is T) "A" else "Unknown"
+2 -2
View File
@@ -4,9 +4,9 @@ class A
class B
class C
inline fun test<reified T, reified R>(x: Any): String = test1<R, T>(x)
inline fun <reified T, reified R> test(x: Any): String = test1<R, T>(x)
inline fun test1<reified R, reified T>(x: Any): String =
inline fun <reified R, reified T> test1(x: Any): String =
when (x) {
is R -> "R"
is T -> "T"
+1 -2
View File
@@ -5,8 +5,7 @@ package foo
class A(val x: Int)
class B(val x: Int)
inline
fun test<reified T>(vararg xs: Any): List<T> {
inline fun <reified T> test(vararg xs: Any): List<T> {
val ts = arrayListOf<T>()
for (x in xs) {
@@ -65,7 +65,7 @@ abstract class Tag(val name: String) : Element() {
val children = ArrayList<Element>()
val attributes = HashMap<String, String>()
protected fun initTag<T : Element>(tag: T, init: T.() -> Unit): T {
protected fun <T : Element> initTag(tag: T, init: T.() -> Unit): T {
tag.init()
children.add(tag)
return tag
@@ -89,7 +89,7 @@ abstract class Tag(val name: String) : Element() {
}
abstract class TagWithText(name: String) : Tag(name) {
fun String.plus() {
operator fun String.unaryPlus() {
children.add(TextElement(this))
}
}