Updated test data and stdlib sources.
This commit is contained in:
@@ -58,7 +58,7 @@ fun box() : String {
|
||||
val filtered = x where { it % 2 == 0 }
|
||||
val xx = x select { it * 2 }
|
||||
var res = 0
|
||||
for (val x in xx)
|
||||
for (x in xx)
|
||||
res += x
|
||||
return if (res == 10100) "OK" else "fail"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun loop(var times : Int) {
|
||||
while(times > 0) {
|
||||
fun loop(times : Int) {
|
||||
var left = times
|
||||
while(left > 0) {
|
||||
val u : (value : Int) -> Unit = {
|
||||
foo(it)
|
||||
}
|
||||
u(times--)
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class C(x: Int, val y : Int) {
|
||||
fun initChild(var x: Int) : java.lang.Object {
|
||||
fun initChild(x0: Int) : java.lang.Object {
|
||||
var x = x0
|
||||
return object : java.lang.Object() {
|
||||
override fun toString(): String? {
|
||||
x = x + y
|
||||
|
||||
@@ -2,7 +2,7 @@ import java.util.*
|
||||
|
||||
fun <T> ArrayList<T>.findAll(predicate: (T) -> Boolean): ArrayList<T> {
|
||||
val result = ArrayList<T>()
|
||||
for(val t in this) {
|
||||
for(t in this) {
|
||||
if (predicate(t)) result.add(t)
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -126,7 +126,8 @@ fun t8() : Boolean {
|
||||
return x == 30.toShort()
|
||||
}
|
||||
|
||||
fun t9(var x: Int) : Boolean {
|
||||
fun t9(x0: Int) : Boolean {
|
||||
var x = x0
|
||||
while(x < 100) {
|
||||
x++
|
||||
}
|
||||
@@ -145,7 +146,8 @@ fun t10() : Boolean {
|
||||
return y == 2
|
||||
}
|
||||
|
||||
fun t11(var x: Int) : Int {
|
||||
fun t11(x0: Int) : Int {
|
||||
var x = x0
|
||||
val foo = {
|
||||
x = x + 1
|
||||
val bar = {
|
||||
|
||||
@@ -23,7 +23,7 @@ class Delegated : Tr by Derived() {
|
||||
}
|
||||
|
||||
|
||||
fun checkAssertions(val illegalStateExpected: Boolean) {
|
||||
fun checkAssertions(illegalStateExpected: Boolean) {
|
||||
val check = AssertionChecker(illegalStateExpected)
|
||||
|
||||
// simple call
|
||||
|
||||
@@ -38,7 +38,9 @@ class D() {
|
||||
|
||||
fun foo(): Unit {}
|
||||
|
||||
fun cannotBe(var <!UNUSED_PARAMETER!>i<!>: Int) {
|
||||
fun cannotBe() {
|
||||
var <!UNUSED_VARIABLE!>i<!>: Int = 5
|
||||
|
||||
<!UNRESOLVED_REFERENCE!>z<!> = 30;
|
||||
<!VARIABLE_EXPECTED!>""<!> = "";
|
||||
<!VARIABLE_EXPECTED!>foo()<!> = Unit.VALUE;
|
||||
@@ -49,7 +51,8 @@ fun cannotBe(var <!UNUSED_PARAMETER!>i<!>: Int) {
|
||||
<!VARIABLE_EXPECTED!>5<!> = 34
|
||||
}
|
||||
|
||||
fun canBe(var i: Int, val j: Int) {
|
||||
fun canBe(i0: Int, j: Int) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>i<!> = i0
|
||||
(i: Int) = <!UNUSED_VALUE!>36<!>
|
||||
(@label i) = <!UNUSED_VALUE!>34<!>
|
||||
|
||||
@@ -60,7 +63,7 @@ fun canBe(var i: Int, val j: Int) {
|
||||
(@ a.a) = 3894
|
||||
}
|
||||
|
||||
fun canBe2(val j: Int) {
|
||||
fun canBe2(j: Int) {
|
||||
(@label <!VAL_REASSIGNMENT!>j<!>) = <!UNUSED_VALUE!>34<!>
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,13 @@ abstract class Sum() : Iteratee<Int, Int>() {
|
||||
}
|
||||
|
||||
abstract class Collection<E> : Iterable<E> {
|
||||
fun iterate<O>(var iteratee : Iteratee<E, O>) : O {
|
||||
fun iterate<O>(iteratee : Iteratee<E, O>) : O {
|
||||
var current = iteratee
|
||||
for (x in this) {
|
||||
val it = iteratee.process(x)
|
||||
val it = current.process(x)
|
||||
if (it.isDone) return it.result
|
||||
iteratee = it
|
||||
current = it
|
||||
}
|
||||
return iteratee.done()
|
||||
return current.done()
|
||||
}
|
||||
}
|
||||
@@ -53,10 +53,8 @@ fun t2() {
|
||||
|
||||
class A() {}
|
||||
|
||||
fun t4(a: A, val b: A, var c: A) {
|
||||
fun t4(a: A) {
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>A()<!>
|
||||
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>A()<!>
|
||||
c = <!UNUSED_VALUE!>A()<!>
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
@@ -190,7 +188,7 @@ class AnonymousInitializers(var a: String, val b: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun reassignFunParams(val a: Int) {
|
||||
fun reassignFunParams(a: Int) {
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>1<!>
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
package kt1219
|
||||
|
||||
fun <T, R> Iterable<T>.fold(var r: R, op: (T, R) -> R) : R {
|
||||
fun <T, R> Iterable<T>.fold(a: R, op: (T, R) -> R) : R {
|
||||
var r = a
|
||||
this.foreach { r = op(it, r) } //unused value here
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
package kt609
|
||||
|
||||
fun test(var a: Int) {
|
||||
a = <!UNUSED_VALUE!>324<!> //should be an 'unused value' warning here
|
||||
fun test(a: Int) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>aa<!> = a
|
||||
aa = <!UNUSED_VALUE!>324<!> //should be an 'unused value' warning here
|
||||
}
|
||||
|
||||
class C() {
|
||||
@@ -16,4 +17,4 @@ open class A() {
|
||||
|
||||
class B() : A() {
|
||||
final override fun foo(s : String) {} //should not be a warning
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@ trait B : A {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
fun bar1(a: A, var b: B) {
|
||||
b = a as B
|
||||
fun bar1(a: A) {
|
||||
var b: B = a as B
|
||||
a.foo()
|
||||
b.foo()
|
||||
}
|
||||
|
||||
fun id(b: B) = b
|
||||
fun bar2(a: A, var b: B) {
|
||||
b = id(a as B)
|
||||
fun bar2(a: A) {
|
||||
var b: B = id(a as B)
|
||||
a.foo()
|
||||
b.foo()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
fun bar1(x: Number, var y: Int) {
|
||||
y += x as Int
|
||||
fun bar1(x: Number, y: Int) {
|
||||
var yy = y
|
||||
yy += x as Int
|
||||
x : Int
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
fun simpleDoWhile(x: Int?, var y: Int) {
|
||||
fun simpleDoWhile(x: Int?, y0: Int) {
|
||||
var y = y0
|
||||
do {
|
||||
x : Int?
|
||||
y++
|
||||
@@ -6,7 +7,8 @@ fun simpleDoWhile(x: Int?, var y: Int) {
|
||||
x : Int
|
||||
}
|
||||
|
||||
fun doWhileWithBreak(x: Int?, var y: Int) {
|
||||
fun doWhileWithBreak(x: Int?, y0: Int) {
|
||||
var y = y0
|
||||
do {
|
||||
x : Int?
|
||||
y++
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
fun simpleWhile(x: Int?, var y: Int) {
|
||||
fun simpleWhile(x: Int?, y0: Int) {
|
||||
var y = y0
|
||||
while (x!! == y) {
|
||||
x : Int
|
||||
y++
|
||||
@@ -6,7 +7,8 @@ fun simpleWhile(x: Int?, var y: Int) {
|
||||
x : Int
|
||||
}
|
||||
|
||||
fun whileWithBreak(x: Int?, var y: Int) {
|
||||
fun whileWithBreak(x: Int?, y0: Int) {
|
||||
var y = y0
|
||||
while (x!! == y) {
|
||||
x : Int
|
||||
break
|
||||
|
||||
@@ -15,7 +15,7 @@ fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(val i: Int, val a: <!UNRESOLVED_REFERENCE!>U<!>) {
|
||||
fun bar(i: Int, a: <!UNRESOLVED_REFERENCE!>U<!>) {
|
||||
val r = if (true) i else <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>
|
||||
val <!UNUSED_VARIABLE!>b<!>: Any = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ public fun <T> MutableCollection<out T>.filterToMy(result : MutableList<in T>, f
|
||||
return this
|
||||
}
|
||||
|
||||
fun foo(result: MutableList<in String>, val collection: MutableCollection<String>, prefix : String){
|
||||
fun foo(result: MutableList<in String>, collection: MutableCollection<String>, prefix : String){
|
||||
collection.filterToMy(result, {it.startsWith(prefix)})
|
||||
}
|
||||
|
||||
fun test(result: MutableList<in Any>, val collection: MutableCollection<String>, prefix : String){
|
||||
fun test(result: MutableList<in Any>, collection: MutableCollection<String>, prefix : String){
|
||||
val c = collection.filterToMy(result, {it.startsWith(prefix)})
|
||||
c: MutableCollection<out String>
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package j
|
||||
|
||||
fun <T : Any> T?.sure() : T = this!!
|
||||
|
||||
fun testArrays(val ci: List<Int?>, val cii: List<Int?>?) {
|
||||
fun testArrays(ci: List<Int?>, cii: List<Int?>?) {
|
||||
val c1: Array<Int?> = cii.sure().toArray(<!FUNCTION_CALL_EXPECTED!><!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>Array<!><Int?><!>)
|
||||
|
||||
val c2: Array<Int?> = ci.toArray(Array<Int?>(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!>)
|
||||
|
||||
@@ -210,7 +210,8 @@ fun f(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
fun foo(var a: Any): Int {
|
||||
fun foo(aa: Any): Int {
|
||||
var a = aa
|
||||
if (a is Int) {
|
||||
return <!AUTOCAST_IMPOSSIBLE!>a<!>
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ class MyElement
|
||||
|
||||
fun test1(collection: MyCollection) {
|
||||
collection.<!OVERLOAD_RESOLUTION_AMBIGUITY!>iterator()<!>
|
||||
for (val element in <!ITERATOR_AMBIGUITY!>collection<!>) {
|
||||
for (element in <!ITERATOR_AMBIGUITY!>collection<!>) {
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ fun main(args: Array<String>) {
|
||||
val numbers = ArrayList<Int>(4)
|
||||
val rnd = Random();
|
||||
val prompt = StringBuilder()
|
||||
for(val i in 0..3) {
|
||||
for(i in 0..3) {
|
||||
val n = rnd.nextInt(9) + 1
|
||||
numbers.add(n)
|
||||
if (i > 0) prompt.append(" ");
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class Item(val room: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!>) {
|
||||
val items: ArrayList<Item> = ArrayList<Item>()
|
||||
|
||||
fun test(room : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Object<!>) {
|
||||
for(val item: Item? in items) {
|
||||
for(item: Item? in items) {
|
||||
if (item?.room === room) {
|
||||
System.out.println("You see " + item?.name)
|
||||
}
|
||||
|
||||
@@ -185,25 +185,25 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testPreDecrement() throws Exception {
|
||||
loadText("fun foo(var a: Int): Int { return --a;}");
|
||||
loadText("fun foo(a0: Int): Int { var a = a0; return --a;}");
|
||||
final Method main = generateFunction();
|
||||
assertEquals(9, main.invoke(null, 10));
|
||||
}
|
||||
|
||||
public void testPreIncrementLong() throws Exception {
|
||||
loadText("fun foo(var a: Long): Long = ++a");
|
||||
loadText("fun foo(a0: Long): Long { var a = a0; return ++a}");
|
||||
final Method main = generateFunction();
|
||||
assertEquals(11L, main.invoke(null, 10L));
|
||||
}
|
||||
|
||||
public void testPreIncrementFloat() throws Exception {
|
||||
loadText("fun foo(var a: Float): Float = ++a");
|
||||
loadText("fun foo(a0: Float): Float { var a = a0; return ++a }");
|
||||
final Method main = generateFunction();
|
||||
assertEquals(2.0f, main.invoke(null, 1.0f));
|
||||
}
|
||||
|
||||
public void testPreIncrementDouble() throws Exception {
|
||||
loadText("fun foo(var a: Double): Double = ++a");
|
||||
loadText("fun foo(a0: Double): Double {var a = a0; return ++a }");
|
||||
final Method main = generateFunction();
|
||||
assertEquals(2.0, main.invoke(null, 1.0));
|
||||
}
|
||||
|
||||
@@ -31,12 +31,13 @@ abstract class Sum() : Iteratee<Int, Int>() {
|
||||
}
|
||||
|
||||
abstract class Collection<E> : Iterable<E> {
|
||||
fun iterate<O>(var iteratee : Iteratee<E, O>) : O {
|
||||
fun iterate<O>(iteratee : Iteratee<E, O>) : O {
|
||||
var current = iteratee
|
||||
for (x in this) {
|
||||
val it = iteratee.process(x)
|
||||
val it = current.process(x)
|
||||
if (it.isDone) return it.result
|
||||
iteratee = it
|
||||
current = it
|
||||
}
|
||||
return iteratee.done()
|
||||
return current.done()
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,8 @@ fun f(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
fun foo(var a: Any): Int {
|
||||
fun foo(aa: Any): Int {
|
||||
var a = aa
|
||||
if (a is Int) {
|
||||
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'jet.Int' is impossible, because 'a' could have changed since the is-check">a</error>
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ fun main(args: Array<String>) {
|
||||
val numbers = ArrayList<Int>(4)
|
||||
val rnd = Random();
|
||||
val prompt = StringBuilder()
|
||||
for(val i in 0..3) {
|
||||
for(i in 0..3) {
|
||||
val n = rnd.nextInt(9) + 1
|
||||
numbers.add(n)
|
||||
if (i > 0) prompt.append(" ");
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class Item(val room: <warning>Object</warning>) {
|
||||
val items: ArrayList<Item> = ArrayList<Item>()
|
||||
|
||||
fun test(room : <warning>Object</warning>) {
|
||||
for(val item: Item in items) {
|
||||
for(item: Item in items) {
|
||||
if (item.room === room) {
|
||||
System.out.println("You see " + item.name)
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ trait X {
|
||||
}
|
||||
|
||||
class B : A(), X {
|
||||
override fun foo(var arg: Int) : Int {
|
||||
arg += 5
|
||||
override fun foo(arg: Int) : Int {
|
||||
val x = arg + arg
|
||||
return arg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ abstract class A {
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(var arg: Int) : Int {
|
||||
arg += 5
|
||||
override fun foo(arg: Int) : Int {
|
||||
var x = arg + arg
|
||||
return arg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ trait X {
|
||||
}
|
||||
|
||||
class B : A(), X {
|
||||
override fun foo(var arg<caret>: Int) : Int {
|
||||
arg += 5
|
||||
override fun foo(arg<caret>: Int) : Int {
|
||||
val x = arg + arg
|
||||
return arg
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ trait X {
|
||||
}
|
||||
|
||||
class B : A(), X {
|
||||
override fun foo(var agr<caret> : Int) : Int {
|
||||
agr += 5
|
||||
override fun foo(agr<caret> : Int) : Int {
|
||||
val x = agr + agr
|
||||
return agr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ abstract class A {
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(var agr<caret> : Int) : Int {
|
||||
agr += 5
|
||||
override fun foo(agr<caret> : Int) : Int {
|
||||
var x = agr + agr
|
||||
return agr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ fun box() : Boolean {
|
||||
a1[3] = 3
|
||||
a1[5] = 5
|
||||
|
||||
for (var a : Int? in a1) {
|
||||
for (a : Int? in a1) {
|
||||
if (a != null) {
|
||||
c += 1;
|
||||
} else {
|
||||
|
||||
@@ -2,12 +2,13 @@ package foo
|
||||
|
||||
var b = 0
|
||||
|
||||
fun loop(var times: Int) {
|
||||
while (times > 0) {
|
||||
fun loop(times: Int) {
|
||||
var left = times
|
||||
while (left > 0) {
|
||||
val u = {(value: Int) ->
|
||||
b = b + 1
|
||||
}
|
||||
u(times--)
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ package foo
|
||||
|
||||
var c = 2
|
||||
|
||||
fun loop(var times : Int) {
|
||||
while(times > 0) {
|
||||
fun loop(times : Int) {
|
||||
var left = times
|
||||
while(left > 0) {
|
||||
val u : (value : Int) -> Unit = {
|
||||
c++
|
||||
}
|
||||
u(times--)
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.*
|
||||
|
||||
fun <T> ArrayList<T>.findAll(predicate: (T) -> Boolean): ArrayList<T> {
|
||||
val result = ArrayList<T>()
|
||||
for(val t in this) {
|
||||
for(t in this) {
|
||||
if (predicate(t)) result.add(t)
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -495,6 +495,6 @@ class Vector(val x: Double = 0.0, val y: Double = 0.0) {
|
||||
get() = this * (1.0 / Math.sqrt(sqr))
|
||||
}
|
||||
|
||||
fun getRandomArbitary(val min: Int, val max: Int): Double {
|
||||
fun getRandomArbitary(min: Int, max: Int): Double {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public fun <T> Iterable<T>.containsItem(item : T) : Boolean {
|
||||
return this.contains(item);
|
||||
}
|
||||
|
||||
for (var elem in this) {
|
||||
for (elem in this) {
|
||||
if (elem == item) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public inline fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int {
|
||||
/**
|
||||
* Creates a comparator using the sequence of functions used to calculate a value to compare on
|
||||
*/
|
||||
public inline fun <T> comparator(vararg val functions: T.() -> Comparable<*>?): Comparator<T> {
|
||||
public inline fun <T> comparator(vararg functions: T.() -> Comparable<*>?): Comparator<T> {
|
||||
return FunctionComparator<T>(*functions)
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public fun StringTemplate.toHtml(formatter : HtmlFormatter = HtmlFormatter()) :
|
||||
* to escape particular characters in different output formats such as [[HtmlFormatter]
|
||||
*/
|
||||
public trait Formatter {
|
||||
public fun format(buffer : Appendable, val value : Any?) : Unit
|
||||
public fun format(buffer : Appendable, value : Any?) : Unit
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package test.arrays
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
fun <T> checkContent(val iter : Iterator<T>, val length : Int, val value : (Int) -> T) {
|
||||
fun <T> checkContent(iter : Iterator<T>, length : Int, value : (Int) -> T) {
|
||||
var idx = 0
|
||||
while (idx != length && iter.hasNext()) {
|
||||
assertEquals(value(idx++), iter.next(), "Invalid element")
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ class SyntaxHighligher() {
|
||||
val styleMap = createStyleMap()
|
||||
|
||||
/** Highlights the given kotlin code as HTML */
|
||||
fun highlight(val code: String): String {
|
||||
fun highlight(code: String): String {
|
||||
try {
|
||||
val builder = StringBuilder()
|
||||
builder.append(
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ abstract class KDocTemplate() : TextTemplate() {
|
||||
}
|
||||
}
|
||||
|
||||
open fun typeArguments(arguments: List<KType>, val prefix: String = "<", val postfix: String = ">", val empty: String = ""): String {
|
||||
open fun typeArguments(arguments: List<KType>, prefix: String = "<", postfix: String = ">", empty: String = ""): String {
|
||||
val text = arguments.map<KType, String>() { link(it) }.makeString(", ")
|
||||
return if (text.length() == 0) empty else "$prefix$text$postfix"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user