Stdlib compilation error fixes with new diagnostics

This commit is contained in:
Mikhael Bogdanov
2013-11-11 15:52:14 +04:00
parent 339e639135
commit 1dba69186c
18 changed files with 75 additions and 67 deletions
+9 -9
View File
@@ -75,17 +75,17 @@ public inline fun FloatArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays
public inline fun DoubleArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays.sort(this, fromIndex, toIndex)
public inline fun CharArray.sort(fromIndex: Int, toIndex: Int) : Unit = Arrays.sort(this, fromIndex, toIndex)
public inline fun BooleanArray.copyOf(newLength: Int = this.size) : BooleanArray = Arrays.copyOf(this, newLength)
public inline fun ByteArray.copyOf(newLength: Int = this.size) : ByteArray = Arrays.copyOf(this, newLength)
public inline fun ShortArray.copyOf(newLength: Int = this.size) : ShortArray = Arrays.copyOf(this, newLength)
public inline fun IntArray.copyOf(newLength: Int = this.size) : IntArray = Arrays.copyOf(this, newLength)
public inline fun LongArray.copyOf(newLength: Int = this.size) : LongArray = Arrays.copyOf(this, newLength)
public inline fun FloatArray.copyOf(newLength: Int = this.size) : FloatArray = Arrays.copyOf(this, newLength)
public inline fun DoubleArray.copyOf(newLength: Int = this.size) : DoubleArray = Arrays.copyOf(this, newLength)
public inline fun CharArray.copyOf(newLength: Int = this.size) : CharArray = Arrays.copyOf(this, newLength)
public fun BooleanArray.copyOf(newLength: Int = this.size) : BooleanArray = Arrays.copyOf(this, newLength)
public fun ByteArray.copyOf(newLength: Int = this.size) : ByteArray = Arrays.copyOf(this, newLength)
public fun ShortArray.copyOf(newLength: Int = this.size) : ShortArray = Arrays.copyOf(this, newLength)
public fun IntArray.copyOf(newLength: Int = this.size) : IntArray = Arrays.copyOf(this, newLength)
public fun LongArray.copyOf(newLength: Int = this.size) : LongArray = Arrays.copyOf(this, newLength)
public fun FloatArray.copyOf(newLength: Int = this.size) : FloatArray = Arrays.copyOf(this, newLength)
public fun DoubleArray.copyOf(newLength: Int = this.size) : DoubleArray = Arrays.copyOf(this, newLength)
public fun CharArray.copyOf(newLength: Int = this.size) : CharArray = Arrays.copyOf(this, newLength)
// TODO: resuling array may contain nulls even if T is non-nullable
public inline fun <T> Array<T>.copyOf(newLength: Int = this.size) : Array<T> = Arrays.copyOf(this, newLength) as Array<T>
public fun <T> Array<T>.copyOf(newLength: Int = this.size) : Array<T> = Arrays.copyOf(this, newLength) as Array<T>
public inline fun BooleanArray.copyOfRange(from: Int, to: Int) : BooleanArray = Arrays.copyOfRange(this, from, to)
public inline fun ByteArray.copyOfRange(from: Int, to: Int) : ByteArray = Arrays.copyOfRange(this, from, to)
+4 -2
View File
@@ -2,13 +2,15 @@ package kotlin
private object _Assertions
private val ASSERTIONS_ENABLED = _Assertions.javaClass.desiredAssertionStatus()
deprecated("Must be puplic to make assert() inlinable")
public val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus()
/**
* Throws an [[AssertionError]] with an optional *message* if the *value* is false
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
*/
public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
public fun assert(value: Boolean, message: Any = "Assertion failed") {
if (ASSERTIONS_ENABLED) {
if (!value) {
throw AssertionError(message)
@@ -23,7 +23,7 @@ public fun <T> Iterable<T>.count() : Int {
return number
}
private fun <T> countTo(n: Int): (T) -> Boolean {
public fun <T> countTo(n: Int): (T) -> Boolean {
var count = 0
return { ++count; count <= n }
}
+4 -4
View File
@@ -7,7 +7,7 @@ import kotlin.test.assertTrue
/**
* Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null*
*/
public inline fun <T:Any> iterate(nextFunction: () -> T?) : Iterator<T> {
public fun <T:Any> iterate(nextFunction: () -> T?) : Iterator<T> {
return FunctionIterator(nextFunction)
}
@@ -15,7 +15,7 @@ public inline fun <T:Any> iterate(nextFunction: () -> T?) : Iterator<T> {
* Returns an iterator which invokes the function to calculate the next value based on the previous one on each iteration
* until the function returns *null*
*/
public inline fun <T: Any> iterate(initialValue: T, nextFunction: (T) -> T?): Iterator<T> =
public /*inline*/ fun <T: Any> iterate(initialValue: T, nextFunction: (T) -> T?): Iterator<T> =
iterate(nextFunction.toGenerator(initialValue))
/**
@@ -26,7 +26,7 @@ public inline fun <T, S> Iterator<T>.zip(iterator: Iterator<S>): Iterator<Pair<T
/**
* Returns an iterator shifted to right by the given number of elements
*/
public inline fun <T> Iterator<T>.skip(n: Int): Iterator<T> = SkippingIterator(this, n)
public fun <T> Iterator<T>.skip(n: Int): Iterator<T> = SkippingIterator(this, n)
class FilterIterator<T>(val iterator : Iterator<T>, val predicate: (T)-> Boolean) : AbstractIterator<T>() {
override protected fun computeNext(): Unit {
@@ -203,7 +203,7 @@ class SkippingIterator<T>(val iterator: Iterator<T>, val n: Int): Iterator<T> {
}
}
fun <T: Any> Function1<T, T?>.toGenerator(initialValue: T): Function0<T?> {
public fun <T: Any> Function1<T, T?>.toGenerator(initialValue: T): Function0<T?> {
var nextValue: T? = initialValue
return {
nextValue?.let { result ->
+1 -1
View File
@@ -3,7 +3,7 @@ package kotlin
import kotlin.support.*
/** Returns an iterator over elements that are instances of a given type *R* which is a subclass of *T* */
public inline fun <T, R: T> Iterator<T>.filterIsInstance(klass: Class<R>): Iterator<R> = FilterIsIterator<T,R>(this, klass)
public fun <T, R: T> Iterator<T>.filterIsInstance(klass: Class<R>): Iterator<R> = FilterIsIterator<T,R>(this, klass)
private class FilterIsIterator<T, R :T>(val iterator : Iterator<T>, val klass: Class<R>) : AbstractIterator<R>() {
override protected fun computeNext(): Unit {
+4 -4
View File
@@ -3,17 +3,17 @@ package kotlin
import java.util.*
/** Returns the size of the collection */
val Collection<*>.size : Int
public val Collection<*>.size : Int
get() = size()
/** Returns true if this collection is empty */
val Collection<*>.empty : Boolean
public val Collection<*>.empty : Boolean
get() = isEmpty()
val Collection<*>.indices : IntRange
public val Collection<*>.indices : IntRange
get() = 0..size-1
val Int.indices: IntRange
public val Int.indices: IntRange
get() = 0..this-1
/** Returns true if the collection is not empty */
+4 -4
View File
@@ -6,11 +6,11 @@ import java.util.HashMap
// Map APIs
/** Returns the size of the map */
val Map<*,*>.size : Int
public val Map<*,*>.size : Int
get() = size()
/** Returns true if this map is empty */
val Map<*,*>.empty : Boolean
public val Map<*,*>.empty : Boolean
get() = isEmpty()
/** Provides [] access to maps */
@@ -22,11 +22,11 @@ public inline fun <K,V> Map<K,V>?.orEmpty() : Map<K,V>
/** Returns the key of the entry */
val <K,V> Map.Entry<K,V>.key : K
public val <K,V> Map.Entry<K,V>.key : K
get() = getKey()
/** Returns the value of the entry */
val <K,V> Map.Entry<K,V>.value : V
public val <K,V> Map.Entry<K,V>.value : V
get() = getValue()
/** Returns the key of the entry */
+1 -1
View File
@@ -34,7 +34,7 @@ public inline fun <K,V> Map<K,V>.toSortedMap(comparator: Comparator<K>): SortedM
*
* @includeFunctionBody ../../test/MapTest.kt toProperties
*/
public inline fun Map<String, String>.toProperties(): Properties {
public fun Map<String, String>.toProperties(): Properties {
val answer = Properties()
for (e in this) {
answer.put(e.key, e.value)
+2 -2
View File
@@ -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 functions: T.() -> Comparable<*>?): Comparator<T> {
public fun <T> comparator(vararg functions: T.() -> Comparable<*>?): Comparator<T> {
return FunctionComparator<T>(*functions)
}
@@ -59,7 +59,7 @@ private class FunctionComparator<T>(vararg val functions: T.() -> Comparable<*>?
/**
* Creates a comparator using the sequence of functions used to calculate a value to compare on
*/
public inline fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {
public fun <T> comparator(fn: (T,T) -> Int): Comparator<T> {
return Function2Comparator<T>(fn)
}
private class Function2Comparator<T>(val compareFn: (T,T) -> Int): Comparator<T> {
+5 -5
View File
@@ -9,7 +9,7 @@ import java.lang.IllegalStateException
*
* @includeFunctionBody ../../test/PreconditionsTest.kt failingRequireWithMessage
*/
public inline fun require(value: Boolean, message: Any = "Failed requirement"): Unit {
public fun require(value: Boolean, message: Any = "Failed requirement"): Unit {
if (!value) {
throw IllegalArgumentException(message.toString())
}
@@ -33,7 +33,7 @@ public inline fun require(value: Boolean, lazyMessage: () -> String): Unit {
*
* @includeFunctionBody ../../test/PreconditionsTest.kt requireNotNull
*/
public inline fun <T:Any> requireNotNull(value: T?, message: Any = "Required value was null"): T {
public fun <T:Any> requireNotNull(value: T?, message: Any = "Required value was null"): T {
if (value == null) {
throw IllegalArgumentException(message.toString())
} else {
@@ -46,7 +46,7 @@ public inline fun <T:Any> requireNotNull(value: T?, message: Any = "Required val
*
* @includeFunctionBody ../../test/PreconditionsTest.kt failingCheckWithMessage
*/
public inline fun check(value: Boolean, message: Any = "Check failed"): Unit {
public fun check(value: Boolean, message: Any = "Check failed"): Unit {
if (!value) {
throw IllegalStateException(message.toString())
}
@@ -70,7 +70,7 @@ public inline fun check(value: Boolean, lazyMessage: () -> String): Unit {
*
* @includeFunctionBody ../../test/PreconditionsTest.kt checkNotNull
*/
public inline fun <T:Any> checkNotNull(value: T?, message: String = "Required value was null"): T {
public fun <T:Any> checkNotNull(value: T?, message: String = "Required value was null"): T {
if (value == null) {
throw IllegalStateException(message)
} else {
@@ -78,4 +78,4 @@ public inline fun <T:Any> checkNotNull(value: T?, message: String = "Required va
}
}
public inline fun error(message: String): Nothing = throw RuntimeException(message)
public fun error(message: String): Nothing = throw RuntimeException(message)
+2 -2
View File
@@ -42,7 +42,7 @@ public inline fun Throwable.printStackTrace(stream: PrintStream): Unit {
/**
* A helper method for creating a [[Callable]] from a function
*/
public inline fun <T> callable(action: ()-> T): Callable<T> {
public /*inline*/ fun <T> callable(action: ()-> T): Callable<T> {
return object: Callable<T> {
public override fun call() = action()
}
@@ -51,7 +51,7 @@ public inline fun <T> callable(action: ()-> T): Callable<T> {
/**
* A helper method for creating a [[Runnable]] from a function
*/
public inline fun runnable(action: ()-> Unit): Runnable {
public /*inline*/ fun runnable(action: ()-> Unit): Runnable {
return object: Runnable {
public override fun run() {
action()
+1 -1
View File
@@ -35,7 +35,7 @@ public inline fun String?.isNotEmpty() : Boolean = this != null && this.length()
/**
Iterator for characters of given CharSequence
*/
public inline fun CharSequence.iterator() : CharIterator = object: jet.CharIterator() {
public fun CharSequence.iterator() : CharIterator = object: jet.CharIterator() {
private var index = 0
public override fun nextChar(): Char = get(index++)
+4 -4
View File
@@ -147,7 +147,7 @@ public inline fun CharSequence.toString() : String? = (this as java.lang.CharSeq
public inline fun CharSequence.length() : Int = (this as java.lang.CharSequence).length()
public inline fun String.toByteArray(encoding: String = Charset.defaultCharset().name()): ByteArray = (this as java.lang.String).getBytes(encoding)
public fun String.toByteArray(encoding: String = Charset.defaultCharset().name()): ByteArray = (this as java.lang.String).getBytes(encoding)
public inline fun String.toByteArray(encoding: Charset): ByteArray = (this as java.lang.String).getBytes(encoding)
public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)
@@ -162,7 +162,7 @@ public inline fun String.toDouble() : Double = java.lang.Double.parseDouble(this
* with the specified flags from [[Pattern]] or'd together
* so that strings can be split or matched on.
*/
public inline fun String.toRegex(flags: Int=0): java.util.regex.Pattern {
public fun String.toRegex(flags: Int=0): java.util.regex.Pattern {
return java.util.regex.Pattern.compile(this, flags)
}
@@ -283,7 +283,7 @@ public inline fun String.any(predicate: (Char) -> Boolean): Boolean {
*
* @includeFunctionBody ../../test/StringTest.kt appendString
*/
public inline fun String.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit {
public fun String.appendString(buffer: Appendable, separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): Unit {
buffer.append(prefix)
var count = 0
for (c in this) {
@@ -441,7 +441,7 @@ public inline fun <K> String.groupByTo(result: MutableMap<K, String>, toKey: (Ch
*
* @includeFunctionBody ../../test/StringTest.kt makeString
*/
public inline fun String.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
public fun String.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String {
val buffer = StringBuilder()
appendString(buffer, separator, prefix, postfix, limit, truncated)
return buffer.toString()
@@ -8,7 +8,7 @@ import java.beans.*
/**
* Creates a [[PropertyChangeListener]] for the given function for processing each [[PropertyChangeEvent]]
*/
inline fun propertyChangeListener(fn: (PropertyChangeEvent) -> Unit): PropertyChangeListener = FunctionPropertyChangeListener(fn)
fun propertyChangeListener(fn: (PropertyChangeEvent) -> Unit): PropertyChangeListener = FunctionPropertyChangeListener(fn)
private class FunctionPropertyChangeListener(val fn: (PropertyChangeEvent) -> Unit) : PropertyChangeListener {
public override fun propertyChange(e: PropertyChangeEvent) {
@@ -49,7 +49,7 @@ public fun thread(start: Boolean = true, daemon: Boolean = false, contextClassLo
/**
* Executes the given block on the [[Executor]]
*/
public inline fun Executor.execute(action: ()->Unit) {
public /*inline*/ fun Executor.execute(action: ()->Unit) {
execute(runnable(action))
}
@@ -57,14 +57,14 @@ public inline fun Executor.execute(action: ()->Unit) {
* Allows you to use the executor as a function to
* execute the given block on the [[Executor]].
*/
public inline fun Executor.invoke(action: ()->Unit) {
public /*inline*/ fun Executor.invoke(action: ()->Unit) {
execute(runnable(action))
}
/**
* Executes the given block on the [[Executor]]
*/
public inline fun <T>ExecutorService.submit(action: ()->T):Future<T> {
public /*inline*/ fun <T>ExecutorService.submit(action: ()->T):Future<T> {
val c:Callable<T> = callable(action)
return submit(c);
}
@@ -73,6 +73,6 @@ public inline fun <T>ExecutorService.submit(action: ()->T):Future<T> {
* Allows you to use the executor as a function to
* execute the given block on the [[Executor]].
*/
public inline fun <T>ExecutorService.invoke(action: ()->T):Future<T> {
public /*inline*/ fun <T>ExecutorService.invoke(action: ()->T):Future<T> {
return submit(action)
}
+10 -10
View File
@@ -141,7 +141,7 @@ private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : I
}))
/** Reads a line of input from [[System.in]] */
public inline fun readLine() : String? = stdin.readLine()
public fun readLine() : String? = stdin.readLine()
/** Uses the given resource then closes it down correctly whether an exception is thrown or not */
public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
@@ -178,33 +178,33 @@ object: ByteIterator() {
}
/** Creates a buffered input stream */
public inline fun InputStream.buffered(bufferSize: Int = defaultBufferSize) : InputStream
public fun InputStream.buffered(bufferSize: Int = defaultBufferSize) : InputStream
= if (this is BufferedInputStream)
this
else
BufferedInputStream(this, bufferSize)
public inline fun InputStream.reader(encoding: Charset = defaultCharset) : InputStreamReader = InputStreamReader(this, encoding)
public fun InputStream.reader(encoding: Charset = defaultCharset) : InputStreamReader = InputStreamReader(this, encoding)
public inline fun InputStream.reader(encoding: String) : InputStreamReader = InputStreamReader(this, encoding)
public inline fun InputStream.reader(encoding: CharsetDecoder) : InputStreamReader = InputStreamReader(this, encoding)
public inline fun OutputStream.buffered(bufferSize: Int = defaultBufferSize) : BufferedOutputStream
public fun OutputStream.buffered(bufferSize: Int = defaultBufferSize) : BufferedOutputStream
= if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize)
public inline fun OutputStream.writer(encoding: Charset = defaultCharset) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public fun OutputStream.writer(encoding: Charset = defaultCharset) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public inline fun OutputStream.writer(encoding: String) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public fun OutputStream.writer(encoding: String) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public inline fun OutputStream.writer(encoding: CharsetEncoder) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public fun OutputStream.writer(encoding: CharsetEncoder) : OutputStreamWriter = OutputStreamWriter(this, encoding)
public inline fun Reader.buffered(bufferSize: Int = defaultBufferSize): BufferedReader
public fun Reader.buffered(bufferSize: Int = defaultBufferSize): BufferedReader
= if(this is BufferedReader) this else BufferedReader(this, bufferSize)
public inline fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter
public fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter
= if(this is BufferedWriter) this else BufferedWriter(this, bufferSize)
@@ -231,7 +231,7 @@ public inline fun <T> Reader.useLines(block: (Iterator<String>) -> T): T = this.
* <br>
* We suggest you try the method useLines() instead which closes the stream when the processing is complete.
*/
public inline fun BufferedReader.lineIterator() : Iterator<String> = LineIterator(this)
public fun BufferedReader.lineIterator() : Iterator<String> = LineIterator(this)
class LineIterator(val reader: BufferedReader) : Iterator<String> {
private var nextValue: String? = null
+17 -11
View File
@@ -13,7 +13,7 @@ public inline fun assertTrue(message: String, block: ()-> Boolean) {
}
/** Asserts that the given block returns true */
public inline fun assertTrue(block: ()-> Boolean) : Unit = assertTrue(block.toString(), block)
public inline fun assertTrue(block: ()-> Boolean) : Unit = assertTrue("exprected true", block)
/** Asserts that the given block returns false */
public inline fun assertNot(message: String, block: ()-> Boolean) {
@@ -21,31 +21,37 @@ public inline fun assertNot(message: String, block: ()-> Boolean) {
}
/** Asserts that the given block returns false */
public inline fun assertNot(block: ()-> Boolean) : Unit = assertNot(block.toString(), block)
public fun assertNot(block: ()-> Boolean) : Unit = assertNot("expected false", block)
/** Asserts that the expression is true with an optional message */
public inline fun assertTrue(actual: Boolean, message: String = "") {
public fun assertTrue(actual: Boolean, message: String = "") {
return assertEquals(true, actual, message)
}
/** Asserts that the expression is false with an optional message */
public inline fun assertFalse(actual: Boolean, message: String = "") {
public fun assertFalse(actual: Boolean, message: String = "") {
return assertEquals(false, actual, message)
}
/** Asserts that the expected value is equal to the actual value, with an optional message */
public inline fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
public fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
asserter.assertEquals(message, expected, actual)
}
/** Asserts that the expression is not null, with an optional message */
public inline fun <T> assertNotNull(actual: T?, message: String = ""): T {
public fun <T> assertNotNull(actual: T?, message: String = ""): T {
asserter.assertNotNull(message, actual)
return actual!!
}
//TODO merge with next via default
/** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */
public inline fun <T, R> assertNotNull(actual: T?, message: String = "", block: (T) -> R) {
public inline fun <T, R> assertNotNull(actual: T?, block: (T) -> R) {
assertNotNull(actual, "", block)
}
/** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */
public inline fun <T, R> assertNotNull(actual: T?, message: String, block: (T) -> R) {
asserter.assertNotNull(message, actual)
if (actual != null) {
block(actual)
@@ -53,18 +59,18 @@ public inline fun <T, R> assertNotNull(actual: T?, message: String = "", block:
}
/** Asserts that the expression is null, with an optional message */
public inline fun assertNull(actual: Any?, message: String = "") {
public fun assertNull(actual: Any?, message: String = "") {
asserter.assertNull(message, actual)
}
/** Marks a test as having failed if this point in the execution path is reached, with an optional message */
public inline fun fail(message: String = "") {
public fun fail(message: String = "") {
asserter.fail(message)
}
/** Asserts that given function block returns the given expected value */
public inline fun <T> expect(expected: T, block: ()-> T) {
expect(expected, block.toString(), block)
expect(expected, "expected " + expected, block)
}
/** Asserts that given function block returns the given expected value and use the given message if it fails */
@@ -88,7 +94,7 @@ public fun fails(block: ()-> Unit): Throwable? {
/**
* A plugin for performing assertions which can reuse JUnit or TestNG
*/
trait Asserter {
public trait Asserter {
public fun assertTrue(message: String, actual: Boolean): Unit
public fun assertEquals(message: String, expected: Any?, actual: Any?): Unit
+1 -1
View File
@@ -21,7 +21,7 @@ public fun <T: Throwable> failsWith(exceptionClass: Class<T>, block: ()-> Any):
* to implement in your unit test output
*/
public inline fun todo(block: ()-> Any) {
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1))
}
private var _asserter: Asserter? = null