fix tests in org.jetbrains.kotlin.js.test.semantics
This commit is contained in:
@@ -3,16 +3,16 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: multiplyInline
|
||||
// CHECK_NOT_CALLED: runNoinline
|
||||
|
||||
inline fun multiply(a: Int, b: Int) = a * b
|
||||
internal inline fun multiply(a: Int, b: Int) = a * b
|
||||
|
||||
inline fun run(a: Int, b: Int, func: (Int, Int) -> Int) = func(a, b)
|
||||
internal inline fun run(a: Int, b: Int, func: (Int, Int) -> Int) = func(a, b)
|
||||
|
||||
fun multiplyInline(a: Int, b: Int) = run(a, b, ::multiply)
|
||||
internal fun multiplyInline(a: Int, b: Int) = run(a, b, ::multiply)
|
||||
|
||||
|
||||
inline fun runNoinline(a: Int, b: Int, noinline func: (Int, Int) -> Int) = func(a, b)
|
||||
internal inline fun runNoinline(a: Int, b: Int, noinline func: (Int, Int) -> Int) = func(a, b)
|
||||
|
||||
fun multiplyNoinline(a: Int, b: Int) = runNoinline(a, b, ::multiply)
|
||||
internal fun multiplyNoinline(a: Int, b: Int) = runNoinline(a, b, ::multiply)
|
||||
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -5,9 +5,9 @@ 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()`.
|
||||
inline fun evaluate<T>(fn: ()->T): T = fn()
|
||||
internal inline fun evaluate<T>(fn: ()->T): T = fn()
|
||||
|
||||
fun test(n: Int): Int {
|
||||
internal fun test(n: Int): Int {
|
||||
return evaluate {
|
||||
var i = n
|
||||
var sum = 0
|
||||
|
||||
@@ -2,11 +2,11 @@ package foo
|
||||
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiply function=multiply$f
|
||||
|
||||
class A(val a: Int)
|
||||
internal class A(val a: Int)
|
||||
|
||||
inline fun <T, R> with2(receiver: T, arg1: R, arg2: R, f: T.(R, R) -> R): R = receiver.f(arg1, arg2)
|
||||
internal inline fun <T, R> with2(receiver: T, arg1: R, arg2: R, f: T.(R, R) -> R): R = receiver.f(arg1, arg2)
|
||||
|
||||
fun multiply(a: Int, b: Int, c: Int): Int = with2(A(a), b, c) { x, y -> a*x*y }
|
||||
internal fun multiply(a: Int, b: Int, c: Int): Int = with2(A(a), b, c) { x, y -> a*x*y }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(105, multiply(3, 5, 7))
|
||||
|
||||
+4
-4
@@ -2,19 +2,19 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: squareMultipliedByTwo
|
||||
|
||||
inline fun inline1(a: Int): Int {
|
||||
internal inline fun inline1(a: Int): Int {
|
||||
return a
|
||||
}
|
||||
|
||||
inline fun inline2(a: Int): Int {
|
||||
internal inline fun inline2(a: Int): Int {
|
||||
return inline1(a) + inline1(a)
|
||||
}
|
||||
|
||||
inline fun inline3(a: Int): Int {
|
||||
internal inline fun inline3(a: Int): Int {
|
||||
return inline1(a) * inline2(a)
|
||||
}
|
||||
|
||||
fun squareMultipliedByTwo(a: Int): Int {
|
||||
internal fun squareMultipliedByTwo(a: Int): Int {
|
||||
return inline3(a)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,24 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: squareMultipliedByTwo
|
||||
|
||||
inline fun inline1(a: Int): Int {
|
||||
internal inline fun inline1(a: Int): Int {
|
||||
return a
|
||||
}
|
||||
|
||||
inline fun inline2(a: Int): Int {
|
||||
internal inline fun inline2(a: Int): Int {
|
||||
val a1 = inline1(a)
|
||||
if (a1 == 0) return 0
|
||||
return a1 + inline1(a)
|
||||
}
|
||||
|
||||
inline fun inline3(a: Int): Int {
|
||||
internal inline fun inline3(a: Int): Int {
|
||||
val i = inline2(a)
|
||||
val i1 = inline1(a) * i
|
||||
if (i == i1) return 0
|
||||
return i1
|
||||
}
|
||||
|
||||
fun squareMultipliedByTwo(a: Int): Int {
|
||||
internal fun squareMultipliedByTwo(a: Int): Int {
|
||||
return inline3(a)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: identity
|
||||
// CHECK_CONTAINS_NO_CALLS: sumNoInline
|
||||
|
||||
inline fun sum(a: Int, b: Int = 0): Int {
|
||||
internal inline fun sum(a: Int, b: Int = 0): Int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
fun identity(a: Int): Int {
|
||||
internal fun identity(a: Int): Int {
|
||||
return sum(a)
|
||||
}
|
||||
|
||||
fun sumNoInline(a: Int, b: Int): Int {
|
||||
internal fun sumNoInline(a: Int, b: Int): Int {
|
||||
return sum(a, b)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: doNothingNoInline
|
||||
|
||||
inline fun <T> doNothing1(a: T): T {
|
||||
internal inline fun <T> doNothing1(a: T): T {
|
||||
return a
|
||||
}
|
||||
|
||||
inline fun <T> doNothing2(a: T, f: (T) -> T): T {
|
||||
internal inline fun <T> doNothing2(a: T, f: (T) -> T): T {
|
||||
return f(a)
|
||||
}
|
||||
|
||||
fun doNothingNoInline(a: Int): Int {
|
||||
internal fun doNothingNoInline(a: Int): Int {
|
||||
return doNothing2(a, { x -> doNothing1(x)})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: doNothingInt
|
||||
// CHECK_CONTAINS_NO_CALLS: doNothingStr
|
||||
|
||||
inline fun <T> doNothing(a: T): T {
|
||||
internal inline fun <T> doNothing(a: T): T {
|
||||
return a
|
||||
}
|
||||
|
||||
fun doNothingInt(a: Int): Int {
|
||||
internal fun doNothingInt(a: Int): Int {
|
||||
return doNothing(a)
|
||||
}
|
||||
|
||||
fun doNothingStr(a: String): String {
|
||||
internal fun doNothingStr(a: String): String {
|
||||
return doNothing(a)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,11 +2,11 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: multiplyNoInline
|
||||
|
||||
inline fun multiply(a: Int, b: Int): Int {
|
||||
internal inline fun multiply(a: Int, b: Int): Int {
|
||||
return a * b
|
||||
}
|
||||
|
||||
fun multiplyNoInline(a: Int, b: Int): Int {
|
||||
internal fun multiplyNoInline(a: Int, b: Int): Int {
|
||||
var c = a - 1
|
||||
var d = b - 1
|
||||
return (c++) + (d++) + multiply(c, d) - (--c + --d)
|
||||
|
||||
@@ -4,7 +4,7 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: doNothing2
|
||||
// CHECK_CONTAINS_NO_CALLS: doNothing3
|
||||
|
||||
class Inline {
|
||||
internal class Inline {
|
||||
public inline fun <T> identity1 (x: T): T {
|
||||
return x
|
||||
}
|
||||
@@ -18,15 +18,15 @@ class Inline {
|
||||
}
|
||||
}
|
||||
|
||||
fun doNothing1 (inline1: Inline, a: Int): Int {
|
||||
internal fun doNothing1 (inline1: Inline, a: Int): Int {
|
||||
return inline1.identity1(a)
|
||||
}
|
||||
|
||||
fun doNothing2 (inline2: Inline, a: Int): Int {
|
||||
internal fun doNothing2 (inline2: Inline, a: Int): Int {
|
||||
return inline2.identity2(a, {it})
|
||||
}
|
||||
|
||||
fun doNothing3 (inline3: Inline): Int {
|
||||
internal fun doNothing3 (inline3: Inline): Int {
|
||||
return inline3.identity3({11})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: sumEven
|
||||
|
||||
inline fun filteredReduce(a: Array<Int>, predicate: (Int) -> Boolean, reduceFun: (Int, Int) -> Int): Int {
|
||||
internal inline fun filteredReduce(a: Array<Int>, predicate: (Int) -> Boolean, reduceFun: (Int, Int) -> Int): Int {
|
||||
var result = 0
|
||||
|
||||
for (element in a) {
|
||||
@@ -15,7 +15,7 @@ inline fun filteredReduce(a: Array<Int>, predicate: (Int) -> Boolean, reduceFun:
|
||||
return result
|
||||
}
|
||||
|
||||
fun sumEven(a: Array<Int>): Int {
|
||||
internal fun sumEven(a: Array<Int>): Int {
|
||||
return filteredReduce(a, { x -> x % 2 == 0}, { x, y -> x + y})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: maxBySquare
|
||||
|
||||
data class Result(var value: Int = 0, var invocationCount: Int = 0)
|
||||
internal data class Result(var value: Int = 0, var invocationCount: Int = 0)
|
||||
|
||||
inline fun maxBy(a: Array<Int>, keyFun: (Int) -> Int): Int {
|
||||
internal inline fun maxBy(a: Array<Int>, keyFun: (Int) -> Int): Int {
|
||||
var maxVal = a[0]
|
||||
var maxKey = keyFun(maxVal)
|
||||
|
||||
@@ -20,7 +20,7 @@ inline fun maxBy(a: Array<Int>, keyFun: (Int) -> Int): Int {
|
||||
return maxVal
|
||||
}
|
||||
|
||||
fun maxBySquare(a: Array<Int>, r: Result): Result {
|
||||
internal fun maxBySquare(a: Array<Int>, r: Result): Result {
|
||||
var invocationCount = 0
|
||||
val maxVal = maxBy(a, { x -> invocationCount++; x * x;})
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: add
|
||||
|
||||
data class IntPair(public var fst: Int, public var snd: Int) {
|
||||
internal data class IntPair(public var fst: Int, public var snd: Int) {
|
||||
inline public fun getFst(): Int { return fst }
|
||||
inline public fun setFst(v: Int) { fst = v }
|
||||
|
||||
@@ -10,7 +10,7 @@ data class IntPair(public var fst: Int, public var snd: Int) {
|
||||
inline public fun setSnd(v: Int) { this.snd = v }
|
||||
}
|
||||
|
||||
fun add(p: IntPair, toFst: Int, toSnd: Int) {
|
||||
internal fun add(p: IntPair, toFst: Int, toSnd: Int) {
|
||||
val fst = p.getFst()
|
||||
p.setFst(fst + toFst)
|
||||
|
||||
|
||||
@@ -2,22 +2,22 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: factAbsNoInline1
|
||||
|
||||
class State(value: Int) {
|
||||
internal class State(value: Int) {
|
||||
public var value: Int = value
|
||||
}
|
||||
|
||||
inline fun multiply(state: State, factor: Int) {
|
||||
internal inline fun multiply(state: State, factor: Int) {
|
||||
state.value *= factor
|
||||
}
|
||||
|
||||
inline fun abs(state: State) {
|
||||
internal inline fun abs(state: State) {
|
||||
val value = state.value
|
||||
if (value < 0) {
|
||||
multiply(state, -1)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun factAbs(state: State) {
|
||||
internal inline fun factAbs(state: State) {
|
||||
abs(state)
|
||||
|
||||
if (state.value == 0) {
|
||||
@@ -32,12 +32,12 @@ inline fun factAbs(state: State) {
|
||||
}
|
||||
}
|
||||
|
||||
fun factAbsNoInline1(state: State): Int {
|
||||
internal fun factAbsNoInline1(state: State): Int {
|
||||
factAbs(state)
|
||||
return state.value
|
||||
}
|
||||
|
||||
fun factAbsNoInline2(n: Int): Int {
|
||||
internal fun factAbsNoInline2(n: Int): Int {
|
||||
return factAbsNoInline1(State(n))
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
inline fun sum(x: Int, y: Int): Int = js("x + y")
|
||||
internal inline fun sum(x: Int, y: Int): Int = js("x + y")
|
||||
|
||||
fun test(x: Int, y: Int): Int = sum(sum(x, x), sum(y, y))
|
||||
internal fun test(x: Int, y: Int): Int = sum(sum(x, x), sum(y, y))
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(4, test(1, 1))
|
||||
|
||||
@@ -2,9 +2,9 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
inline fun sum(x: Int, y: Int): Int = js("var a = x; a + y")
|
||||
internal inline fun sum(x: Int, y: Int): Int = js("var a = x; a + y")
|
||||
|
||||
fun test(x: Int, y: Int): Int {
|
||||
internal fun test(x: Int, y: Int): Int {
|
||||
val xx = sum(x, x)
|
||||
js("var a = 0;")
|
||||
val yy = sum(y, y)
|
||||
|
||||
@@ -4,11 +4,11 @@ package foo
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=multiplyBy2$f_0
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=run
|
||||
|
||||
inline fun runLambdaInLambda<T>(noinline inner: (T) -> T, outer: ((T) -> T, T) -> T, arg: T): T {
|
||||
internal inline fun runLambdaInLambda<T>(noinline inner: (T) -> T, outer: ((T) -> T, T) -> T, arg: T): T {
|
||||
return outer(inner, arg)
|
||||
}
|
||||
|
||||
fun multiplyBy2(x: Int): Int {
|
||||
internal fun multiplyBy2(x: Int): Int {
|
||||
return runLambdaInLambda({ it * 2 }, { f, x -> f(x) }, x)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: capturedInLambda
|
||||
// CHECK_CONTAINS_NO_CALLS: declaredInLambda
|
||||
|
||||
data class State(var count: Int = 0)
|
||||
internal data class State(var count: Int = 0)
|
||||
|
||||
inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
internal inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
for (i in 1..times) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
fun capturedInLambda(state: State, a: Int, b: Int): Int {
|
||||
internal fun capturedInLambda(state: State, a: Int, b: Int): Int {
|
||||
@inline fun State.inc() {
|
||||
count++
|
||||
}
|
||||
@@ -24,7 +24,7 @@ fun capturedInLambda(state: State, a: Int, b: Int): Int {
|
||||
}
|
||||
|
||||
|
||||
fun declaredInLambda(state: State, a: Int, b: Int): Int {
|
||||
internal fun declaredInLambda(state: State, a: Int, b: Int): Int {
|
||||
repeatAction(a) {
|
||||
@inline fun State.inc() {
|
||||
count++
|
||||
|
||||
@@ -3,13 +3,13 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: localWithCapture
|
||||
// CHECK_CONTAINS_NO_CALLS: localWithoutCapture
|
||||
|
||||
inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
internal inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
for (i in 1..times) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
internal fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
var sum = 0
|
||||
|
||||
@inline fun inc(x: Int): Int {
|
||||
@@ -23,7 +23,7 @@ fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
fun localWithCapture(a: Int, b: Int): Int {
|
||||
internal fun localWithCapture(a: Int, b: Int): Int {
|
||||
var sum = 0
|
||||
|
||||
@inline fun inc() {
|
||||
|
||||
@@ -2,15 +2,15 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: add
|
||||
|
||||
data class State(var count: Int = 0)
|
||||
internal data class State(var count: Int = 0)
|
||||
|
||||
inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
internal inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
for (i in 1..times) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
fun add(state: State, a: Int, b: Int): Int {
|
||||
internal fun add(state: State, a: Int, b: Int): Int {
|
||||
@inline fun inc(a: Int): Int {
|
||||
return a + 1
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,13 +3,13 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: localWithCapture
|
||||
// CHECK_CONTAINS_NO_CALLS: localWithoutCapture
|
||||
|
||||
inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
internal inline fun repeatAction(times: Int, action: () -> Unit) {
|
||||
for (i in 1..times) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
internal fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
var mult = 0
|
||||
|
||||
repeatAction(a) {
|
||||
@@ -25,7 +25,7 @@ fun localWithoutCapture(a: Int, b: Int): Int {
|
||||
return mult
|
||||
}
|
||||
|
||||
fun localWithCapture(a: Int, b: Int): Int {
|
||||
internal fun localWithCapture(a: Int, b: Int): Int {
|
||||
var mult = 0
|
||||
|
||||
repeatAction(a) {
|
||||
|
||||
@@ -2,11 +2,11 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: add
|
||||
|
||||
inline fun run(action: () -> Int): Int {
|
||||
internal inline fun run(action: () -> Int): Int {
|
||||
return action()
|
||||
}
|
||||
|
||||
fun add(a: Int, b: Int): Int {
|
||||
internal fun add(a: Int, b: Int): Int {
|
||||
var sum = a + b
|
||||
|
||||
@inline fun getSum(): Int {
|
||||
|
||||
@@ -36,17 +36,17 @@ private object O {
|
||||
}
|
||||
}
|
||||
|
||||
fun test1(x: Int, y: Int): Int = apply(x) { it * y }
|
||||
internal fun test1(x: Int, y: Int): Int = apply(x) { it * y }
|
||||
|
||||
fun test2(m: M, x: Int, y: Int): Int = m.applyM(x) { it * y }
|
||||
internal fun test2(m: M, x: Int, y: Int): Int = m.applyM(x) { it * y }
|
||||
|
||||
fun test3(n: N, x: Int, y: Int): Int = n.applyN(x) { it * y }
|
||||
internal fun test3(n: N, x: Int, y: Int): Int = n.applyN(x) { it * y }
|
||||
|
||||
object LTest : L() {
|
||||
internal object LTest : L() {
|
||||
fun test4(l: L, x: Int, y: Int): Int = l.applyL(x) { it * y }
|
||||
}
|
||||
|
||||
fun test5(x: Int, y: Int): Int = O.OInner.applyO(x) { it * y }
|
||||
internal fun test5(x: Int, y: Int): Int = O.OInner.applyO(x) { it * y }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test1(2, 3))
|
||||
|
||||
@@ -3,11 +3,11 @@ package foo
|
||||
// CHECK_CALLED_IN_SCOPE: scope=multiplyBy2 function=multiplyBy2$f
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=multiplyBy2 function=run
|
||||
|
||||
inline fun run<T>(noinline func: (T) -> T, arg: T): T {
|
||||
internal inline fun run<T>(noinline func: (T) -> T, arg: T): T {
|
||||
return func(arg)
|
||||
}
|
||||
|
||||
fun multiplyBy2(x: Int): Int {
|
||||
internal fun multiplyBy2(x: Int): Int {
|
||||
return run({ it * 2 }, x)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ package foo
|
||||
// CHECK_CONTAINS_NO_CALLS: test2
|
||||
// CHECK_CONTAINS_NO_CALLS: test3
|
||||
|
||||
inline fun concat(vararg strings: String): String {
|
||||
internal inline fun concat(vararg strings: String): String {
|
||||
var result = ""
|
||||
|
||||
for (string in strings) {
|
||||
@@ -15,15 +15,15 @@ inline fun concat(vararg strings: String): String {
|
||||
return result
|
||||
}
|
||||
|
||||
fun test1(): String {
|
||||
internal fun test1(): String {
|
||||
return concat()
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
internal fun test2(): String {
|
||||
return concat("a", "b", "c")
|
||||
}
|
||||
|
||||
fun test3(list: Array<String>): String {
|
||||
internal fun test3(list: Array<String>): String {
|
||||
return concat(*list)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user