JS: added inline stdlib cases
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: with_dbz3ex
|
||||
|
||||
fun f(x: Int): Int = x * 2
|
||||
|
||||
fun Int.f(): Int = this * 3
|
||||
|
||||
class A(var value: Int) {
|
||||
class object {
|
||||
fun f(): Int = 5
|
||||
}
|
||||
|
||||
fun f(): Int = value
|
||||
}
|
||||
|
||||
fun test(a: A): Int =
|
||||
// TODO: check that with second parameter is named f?
|
||||
with (a) {
|
||||
f(f() + A.f()).f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(90, test(A(10)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
fun test(a: Int, b: Int): Int {
|
||||
var c = 0
|
||||
|
||||
b.times {
|
||||
c += a
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(6, test(2, 3))
|
||||
assertEquals(6, test(3, 2))
|
||||
assertEquals(20, test(4, 5))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
val Int.abs: Int
|
||||
get() = if (this >= 0) this else -this
|
||||
|
||||
fun test(xs: List<Int>): List<Int> =
|
||||
xs.sortBy(comparator {(a, b) -> a.abs.compareTo(b.abs) })
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf(1, -2, 3, -4), test(listOf(-2, 1, -4, 3)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
fun test(a: Int, b: Int): Int {
|
||||
var res = 0
|
||||
|
||||
with (a + b) {
|
||||
val t = this
|
||||
|
||||
t.times {
|
||||
res += t - b
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(10, test(2, 3))
|
||||
assertEquals(15, test(3, 2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
fun test(x: Int, y: Int): Int =
|
||||
with (x + x) {
|
||||
val xx = this
|
||||
|
||||
with (y + y) {
|
||||
xx + this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(10, test(2, 3))
|
||||
assertEquals(18, test(4, 5))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
|
||||
var counter = 0
|
||||
|
||||
fun test(a: Int) {
|
||||
a.times {
|
||||
counter += 1
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(0, counter)
|
||||
test(5)
|
||||
assertEquals(5, counter)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: testImplicitThis
|
||||
// CHECK_CONTAINS_NO_CALLS: testExplicitThis
|
||||
|
||||
class A(var value: Int)
|
||||
|
||||
fun testImplicitThis(a: A, newValue: Int) {
|
||||
with (a) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
fun testExplicitThis(a: A, newValue: Int) {
|
||||
with (a) {
|
||||
this.value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A(0)
|
||||
assertEquals(0, a.value)
|
||||
|
||||
testImplicitThis(a, 10)
|
||||
assertEquals(10, a.value)
|
||||
|
||||
testExplicitThis(a, 20)
|
||||
assertEquals(20, a.value)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user