Primitive Companion objects do not longer implement IntegerConstants and FloatingPointConstants. All declarations moved inside companions.
IntegerConstants and FloatingPointConstants are dropped. #KT-8897 Fixed
This commit is contained in:
+42
-62
@@ -121,12 +121,12 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
public final operator fun unaryMinus(): kotlin.Int
|
||||
public final operator fun unaryPlus(): kotlin.Int
|
||||
|
||||
public companion object Companion : kotlin.IntegerConstants<kotlin.Byte> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Byte
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Byte
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Byte
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Byte
|
||||
public const final val MAX_VALUE: kotlin.Byte
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Byte
|
||||
public const final val MIN_VALUE: kotlin.Byte
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Byte
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,18 +437,18 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
public final operator fun unaryMinus(): kotlin.Double
|
||||
public final operator fun unaryPlus(): kotlin.Double
|
||||
|
||||
public companion object Companion : kotlin.FloatingPointConstants<kotlin.Double> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ val NEGATIVE_INFINITY: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NEGATIVE_INFINITY>(): kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ val NaN: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NaN>(): kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ val POSITIVE_INFINITY: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-POSITIVE_INFINITY>(): kotlin.Double
|
||||
public final val MAX_VALUE: kotlin.Double
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Double
|
||||
public final val MIN_VALUE: kotlin.Double
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Double
|
||||
public final val NEGATIVE_INFINITY: kotlin.Double
|
||||
public final fun <get-NEGATIVE_INFINITY>(): kotlin.Double
|
||||
public final val NaN: kotlin.Double
|
||||
public final fun <get-NaN>(): kotlin.Double
|
||||
public final val POSITIVE_INFINITY: kotlin.Double
|
||||
public final fun <get-POSITIVE_INFINITY>(): kotlin.Double
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,18 +541,18 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
public final operator fun unaryMinus(): kotlin.Float
|
||||
public final operator fun unaryPlus(): kotlin.Float
|
||||
|
||||
public companion object Companion : kotlin.FloatingPointConstants<kotlin.Float> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ val NEGATIVE_INFINITY: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NEGATIVE_INFINITY>(): kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ val NaN: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NaN>(): kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ val POSITIVE_INFINITY: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-POSITIVE_INFINITY>(): kotlin.Float
|
||||
public final val MAX_VALUE: kotlin.Float
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Float
|
||||
public final val MIN_VALUE: kotlin.Float
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Float
|
||||
public final val NEGATIVE_INFINITY: kotlin.Float
|
||||
public final fun <get-NEGATIVE_INFINITY>(): kotlin.Float
|
||||
public final val NaN: kotlin.Float
|
||||
public final fun <get-NaN>(): kotlin.Float
|
||||
public final val POSITIVE_INFINITY: kotlin.Float
|
||||
public final fun <get-POSITIVE_INFINITY>(): kotlin.Float
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,19 +573,6 @@ public abstract class FloatIterator : kotlin.Iterator<kotlin.Float> {
|
||||
public abstract fun nextFloat(): kotlin.Float
|
||||
}
|
||||
|
||||
public interface FloatingPointConstants</*0*/ T> {
|
||||
public abstract val MAX_VALUE: T
|
||||
public abstract fun <get-MAX_VALUE>(): T
|
||||
public abstract val MIN_VALUE: T
|
||||
public abstract fun <get-MIN_VALUE>(): T
|
||||
public abstract val NEGATIVE_INFINITY: T
|
||||
public abstract fun <get-NEGATIVE_INFINITY>(): T
|
||||
public abstract val NaN: T
|
||||
public abstract fun <get-NaN>(): T
|
||||
public abstract val POSITIVE_INFINITY: T
|
||||
public abstract fun <get-POSITIVE_INFINITY>(): T
|
||||
}
|
||||
|
||||
public interface Function</*0*/ out R> {
|
||||
}
|
||||
|
||||
@@ -654,12 +641,12 @@ public final class Int : kotlin.Number, kotlin.Comparable<kotlin.Int> {
|
||||
public final infix fun ushr(/*0*/ bitCount: kotlin.Int): kotlin.Int
|
||||
public final infix fun xor(/*0*/ other: kotlin.Int): kotlin.Int
|
||||
|
||||
public companion object Companion : kotlin.IntegerConstants<kotlin.Int> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Int
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Int
|
||||
public const final val MAX_VALUE: kotlin.Int
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Int
|
||||
public const final val MIN_VALUE: kotlin.Int
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Int
|
||||
}
|
||||
}
|
||||
|
||||
@@ -747,13 +734,6 @@ public final class IntRange : kotlin.IntProgression, kotlin.ClosedRange<kotlin.I
|
||||
}
|
||||
}
|
||||
|
||||
public interface IntegerConstants</*0*/ T> {
|
||||
public abstract val MAX_VALUE: T
|
||||
public abstract fun <get-MAX_VALUE>(): T
|
||||
public abstract val MIN_VALUE: T
|
||||
public abstract fun <get-MIN_VALUE>(): T
|
||||
}
|
||||
|
||||
public interface Iterable</*0*/ out T> {
|
||||
public abstract operator fun iterator(): kotlin.Iterator<T>
|
||||
}
|
||||
@@ -848,12 +828,12 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
public final infix fun ushr(/*0*/ bitCount: kotlin.Int): kotlin.Long
|
||||
public final infix fun xor(/*0*/ other: kotlin.Long): kotlin.Long
|
||||
|
||||
public companion object Companion : kotlin.IntegerConstants<kotlin.Long> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Long
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Long
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Long
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Long
|
||||
public const final val MAX_VALUE: kotlin.Long
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Long
|
||||
public const final val MIN_VALUE: kotlin.Long
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Long
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,12 +1157,12 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
public final operator fun unaryMinus(): kotlin.Int
|
||||
public final operator fun unaryPlus(): kotlin.Int
|
||||
|
||||
public companion object Companion : kotlin.IntegerConstants<kotlin.Short> {
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val MAX_VALUE: kotlin.Short
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MAX_VALUE>(): kotlin.Short
|
||||
public abstract override /*1*/ /*fake_override*/ val MIN_VALUE: kotlin.Short
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-MIN_VALUE>(): kotlin.Short
|
||||
public const final val MAX_VALUE: kotlin.Short
|
||||
public final fun <get-MAX_VALUE>(): kotlin.Short
|
||||
public const final val MIN_VALUE: kotlin.Short
|
||||
public final fun <get-MIN_VALUE>(): kotlin.Short
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ fun box(): String {
|
||||
testInCall()
|
||||
testDoubleConstants()
|
||||
testFloatConstants()
|
||||
testCallInterface()
|
||||
testLocalFun()
|
||||
testTopLevelFun()
|
||||
testVarTopField()
|
||||
@@ -60,20 +59,6 @@ fun testFloatConstants() {
|
||||
myAssertEquals(ni, Float.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
fun testCallInterface() {
|
||||
fun <T> floatPointConstants(a: FloatingPointConstants<T>) {
|
||||
val pi = a.POSITIVE_INFINITY
|
||||
val ni = a.NEGATIVE_INFINITY
|
||||
val nan = a.NaN
|
||||
|
||||
myAssertEquals(pi, a.POSITIVE_INFINITY)
|
||||
myAssertEquals(ni, a.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
floatPointConstants(Double)
|
||||
floatPointConstants(Float)
|
||||
}
|
||||
|
||||
fun testLocalFun() {
|
||||
fun Int.Companion.LocalFun() : String = "LocalFun"
|
||||
myAssertEquals("LocalFun", Int.LocalFun())
|
||||
|
||||
@@ -23,7 +23,17 @@ package kotlin
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `byte`.
|
||||
*/
|
||||
public class Byte private () : Number, Comparable<Byte> {
|
||||
companion object : IntegerConstants<Byte> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the minimum value an instance of Byte can have.
|
||||
*/
|
||||
public const val MIN_VALUE: Byte = -128
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of Byte can have.
|
||||
*/
|
||||
public const val MAX_VALUE: Byte = 127
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -159,7 +169,17 @@ public class Byte private () : Number, Comparable<Byte> {
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `short`.
|
||||
*/
|
||||
public class Short private () : Number, Comparable<Short> {
|
||||
companion object : IntegerConstants<Short> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the minimum value an instance of Short can have.
|
||||
*/
|
||||
public const val MIN_VALUE: Short = -32768
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of Short can have.
|
||||
*/
|
||||
public const val MAX_VALUE: Short = 32767
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -295,7 +315,17 @@ public class Short private () : Number, Comparable<Short> {
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `int`.
|
||||
*/
|
||||
public class Int private () : Number, Comparable<Int> {
|
||||
companion object : IntegerConstants<Int> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the minimum value an instance of Int can have.
|
||||
*/
|
||||
public const val MIN_VALUE: Int = -2147483648
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of Int can have.
|
||||
*/
|
||||
public const val MAX_VALUE: Int = 2147483647
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -446,7 +476,17 @@ public class Int private () : Number, Comparable<Int> {
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `long`.
|
||||
*/
|
||||
public class Long private () : Number, Comparable<Long> {
|
||||
companion object : IntegerConstants<Long> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the minimum value an instance of Long can have.
|
||||
*/
|
||||
public const val MIN_VALUE: Long = -9223372036854775807L - 1L
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of Long can have.
|
||||
*/
|
||||
public const val MAX_VALUE: Long = 9223372036854775807L
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -597,7 +637,32 @@ public class Long private () : Number, Comparable<Long> {
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `float`.
|
||||
*/
|
||||
public class Float private () : Number, Comparable<Float> {
|
||||
companion object : FloatingPointConstants<Float> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the smallest *positive* nonzero value of Float.
|
||||
*/
|
||||
public val MIN_VALUE: Float
|
||||
|
||||
/**
|
||||
* A constant holding the largest positive finite value of Float.
|
||||
*/
|
||||
public val MAX_VALUE: Float
|
||||
|
||||
/**
|
||||
* A constant holding the positive infinity value of Float.
|
||||
*/
|
||||
public val POSITIVE_INFINITY: Float
|
||||
|
||||
/**
|
||||
* A constant holding the negative infinity value of Float.
|
||||
*/
|
||||
public val NEGATIVE_INFINITY: Float
|
||||
|
||||
/**
|
||||
* A constant holding the "not a number" value of Float.
|
||||
*/
|
||||
public val NaN: Float
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -725,7 +790,32 @@ public class Float private () : Number, Comparable<Float> {
|
||||
* On the JVM, non-nullable values of this type are represented as values of the primitive type `double`.
|
||||
*/
|
||||
public class Double private () : Number, Comparable<Double> {
|
||||
companion object : FloatingPointConstants<Double> {}
|
||||
companion object {
|
||||
/**
|
||||
* A constant holding the smallest *positive* nonzero value of Double.
|
||||
*/
|
||||
public val MIN_VALUE: Double
|
||||
|
||||
/**
|
||||
* A constant holding the largest positive finite value of Double.
|
||||
*/
|
||||
public val MAX_VALUE: Double
|
||||
|
||||
/**
|
||||
* A constant holding the positive infinity value of Double.
|
||||
*/
|
||||
public val POSITIVE_INFINITY: Double
|
||||
|
||||
/**
|
||||
* A constant holding the negative infinity value of Double.
|
||||
*/
|
||||
public val NEGATIVE_INFINITY: Double
|
||||
|
||||
/**
|
||||
* A constant holding the "not a number" value of Double.
|
||||
*/
|
||||
public val NaN: Double
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin
|
||||
|
||||
/**
|
||||
* An interface implemented by companion objects of floating-point types.
|
||||
*/
|
||||
public interface FloatingPointConstants<T> {
|
||||
/**
|
||||
* A constant holding the smallest *positive* nonzero value.
|
||||
*/
|
||||
public val MIN_VALUE: T
|
||||
|
||||
/**
|
||||
* A constant holding the largest positive finite value.
|
||||
*/
|
||||
public val MAX_VALUE: T
|
||||
|
||||
/**
|
||||
* A constant holding the positive infinity value.
|
||||
*/
|
||||
public val POSITIVE_INFINITY: T
|
||||
|
||||
/**
|
||||
* A constant holding the negative infinity value.
|
||||
*/
|
||||
public val NEGATIVE_INFINITY: T
|
||||
|
||||
/**
|
||||
* A constant holding the "not a number" value.
|
||||
*/
|
||||
public val NaN: T
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin
|
||||
|
||||
/**
|
||||
* An interface implemented by companion objects of integral types.
|
||||
*/
|
||||
public interface IntegerConstants<T> {
|
||||
/**
|
||||
* A constant holding the minimum value an instance of [T] can have.
|
||||
*/
|
||||
public val MIN_VALUE: T
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of [T] can have.
|
||||
*/
|
||||
public val MAX_VALUE: T
|
||||
}
|
||||
@@ -16,40 +16,40 @@
|
||||
|
||||
package kotlin.jvm.internal
|
||||
|
||||
private object DoubleCompanionObject : FloatingPointConstants<Double> {
|
||||
override val MIN_VALUE: Double = java.lang.Double.MIN_VALUE
|
||||
override val MAX_VALUE: Double = java.lang.Double.MAX_VALUE
|
||||
override val POSITIVE_INFINITY : Double = java.lang.Double.POSITIVE_INFINITY
|
||||
override val NEGATIVE_INFINITY : Double = java.lang.Double.NEGATIVE_INFINITY
|
||||
override val NaN : Double = java.lang.Double.NaN
|
||||
private object DoubleCompanionObject {
|
||||
val MIN_VALUE: Double = java.lang.Double.MIN_VALUE
|
||||
val MAX_VALUE: Double = java.lang.Double.MAX_VALUE
|
||||
val POSITIVE_INFINITY : Double = java.lang.Double.POSITIVE_INFINITY
|
||||
val NEGATIVE_INFINITY : Double = java.lang.Double.NEGATIVE_INFINITY
|
||||
val NaN : Double = java.lang.Double.NaN
|
||||
}
|
||||
|
||||
private object FloatCompanionObject : FloatingPointConstants<Float> {
|
||||
override val MIN_VALUE: Float = java.lang.Float.MIN_VALUE
|
||||
override val MAX_VALUE: Float = java.lang.Float.MAX_VALUE
|
||||
override val POSITIVE_INFINITY : Float = java.lang.Float.POSITIVE_INFINITY
|
||||
override val NEGATIVE_INFINITY : Float = java.lang.Float.NEGATIVE_INFINITY
|
||||
override val NaN : Float = java.lang.Float.NaN
|
||||
private object FloatCompanionObject {
|
||||
val MIN_VALUE: Float = java.lang.Float.MIN_VALUE
|
||||
val MAX_VALUE: Float = java.lang.Float.MAX_VALUE
|
||||
val POSITIVE_INFINITY : Float = java.lang.Float.POSITIVE_INFINITY
|
||||
val NEGATIVE_INFINITY : Float = java.lang.Float.NEGATIVE_INFINITY
|
||||
val NaN : Float = java.lang.Float.NaN
|
||||
}
|
||||
|
||||
private object IntCompanionObject : IntegerConstants<Int> {
|
||||
override val MIN_VALUE: Int = java.lang.Integer.MIN_VALUE
|
||||
override val MAX_VALUE: Int = java.lang.Integer.MAX_VALUE
|
||||
private object IntCompanionObject {
|
||||
const val MIN_VALUE: Int = java.lang.Integer.MIN_VALUE
|
||||
const val MAX_VALUE: Int = java.lang.Integer.MAX_VALUE
|
||||
}
|
||||
|
||||
private object LongCompanionObject : IntegerConstants<Long> {
|
||||
override val MIN_VALUE: Long = java.lang.Long.MIN_VALUE
|
||||
override val MAX_VALUE: Long = java.lang.Long.MAX_VALUE
|
||||
private object LongCompanionObject {
|
||||
const val MIN_VALUE: Long = java.lang.Long.MIN_VALUE
|
||||
const val MAX_VALUE: Long = java.lang.Long.MAX_VALUE
|
||||
}
|
||||
|
||||
private object ShortCompanionObject : IntegerConstants<Short> {
|
||||
override val MIN_VALUE: Short = java.lang.Short.MIN_VALUE
|
||||
override val MAX_VALUE: Short = java.lang.Short.MAX_VALUE
|
||||
private object ShortCompanionObject {
|
||||
const val MIN_VALUE: Short = java.lang.Short.MIN_VALUE
|
||||
const val MAX_VALUE: Short = java.lang.Short.MAX_VALUE
|
||||
}
|
||||
|
||||
private object ByteCompanionObject : IntegerConstants<Byte> {
|
||||
override val MIN_VALUE: Byte = java.lang.Byte.MIN_VALUE
|
||||
override val MAX_VALUE: Byte = java.lang.Byte.MAX_VALUE
|
||||
private object ByteCompanionObject {
|
||||
const val MIN_VALUE: Byte = java.lang.Byte.MIN_VALUE
|
||||
const val MAX_VALUE: Byte = java.lang.Byte.MAX_VALUE
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,20 +51,68 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
PrimitiveType.CHAR to "16-bit Unicode character"
|
||||
)
|
||||
|
||||
private fun primitiveConstants(type: PrimitiveType): List<Any> = when (type) {
|
||||
PrimitiveType.INT -> listOf(java.lang.Integer.MIN_VALUE, java.lang.Integer.MAX_VALUE)
|
||||
PrimitiveType.BYTE -> listOf(java.lang.Byte.MIN_VALUE, java.lang.Byte.MAX_VALUE)
|
||||
PrimitiveType.SHORT -> listOf(java.lang.Short.MIN_VALUE, java.lang.Short.MAX_VALUE)
|
||||
PrimitiveType.LONG ->listOf((java.lang.Long.MIN_VALUE + 1).toString() + "L - 1L", java.lang.Long.MAX_VALUE.toString() + "L")
|
||||
// PrimitiveType.DOUBLE -> listOf(java.lang.Double.MIN_VALUE, java.lang.Double.MAX_VALUE, "1.0/0.0", "-1.0/0.0", "0.0/0.0")
|
||||
// PrimitiveType.FLOAT -> listOf(java.lang.Float.MIN_VALUE, java.lang.Float.MAX_VALUE, "1.0F/0.0F", "-1.0F/0.0F", "0.0F/0.0F").map { it as? String ?: "${it}F" }
|
||||
else -> throw IllegalArgumentException("type: $type")
|
||||
}
|
||||
|
||||
override fun generateBody() {
|
||||
for (kind in PrimitiveType.onlyNumeric) {
|
||||
val className = kind.capitalized
|
||||
generateDoc(kind)
|
||||
out.println("public class $className private () : Number, Comparable<$className> {")
|
||||
|
||||
out.print(" companion object")
|
||||
out.print(" companion object ")
|
||||
if (kind == PrimitiveType.FLOAT || kind == PrimitiveType.DOUBLE) {
|
||||
out.print(" : FloatingPointConstants<$className>")
|
||||
//val (minValue, maxValue, posInf, negInf, nan) = primitiveConstants(kind)
|
||||
out.println("""{
|
||||
/**
|
||||
* A constant holding the smallest *positive* nonzero value of $className.
|
||||
*/
|
||||
public val MIN_VALUE: $className
|
||||
|
||||
/**
|
||||
* A constant holding the largest positive finite value of $className.
|
||||
*/
|
||||
public val MAX_VALUE: $className
|
||||
|
||||
/**
|
||||
* A constant holding the positive infinity value of $className.
|
||||
*/
|
||||
public val POSITIVE_INFINITY: $className
|
||||
|
||||
/**
|
||||
* A constant holding the negative infinity value of $className.
|
||||
*/
|
||||
public val NEGATIVE_INFINITY: $className
|
||||
|
||||
/**
|
||||
* A constant holding the "not a number" value of $className.
|
||||
*/
|
||||
public val NaN: $className
|
||||
}
|
||||
""")
|
||||
}
|
||||
if (kind == PrimitiveType.INT || kind == PrimitiveType.LONG || kind == PrimitiveType.SHORT || kind == PrimitiveType.BYTE) {
|
||||
out.print(" : IntegerConstants<$className>")
|
||||
val (minValue, maxValue) = primitiveConstants(kind)
|
||||
out.println("""{
|
||||
/**
|
||||
* A constant holding the minimum value an instance of $className can have.
|
||||
*/
|
||||
public const val MIN_VALUE: $className = $minValue
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an instance of $className can have.
|
||||
*/
|
||||
public const val MAX_VALUE: $className = $maxValue
|
||||
}
|
||||
""")
|
||||
}
|
||||
out.println(" {}\n")
|
||||
|
||||
generateCompareTo(kind)
|
||||
|
||||
|
||||
+12
-12
@@ -28,23 +28,23 @@ PsiJetFileStubImpl[package=kotlin]
|
||||
REFERENCE_EXPRESSION:[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION:[referencedName=Int]
|
||||
CLASS_BODY:
|
||||
OBJECT_DECLARATION:[fqName=kotlin.Int.Companion, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Companion, superNames=[IntegerConstants]]
|
||||
OBJECT_DECLARATION:[fqName=kotlin.Int.Companion, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Companion, superNames=[]]
|
||||
MODIFIER_LIST:[public companion]
|
||||
SUPER_TYPE_LIST:
|
||||
SUPER_TYPE_ENTRY:
|
||||
CLASS_BODY:
|
||||
PROPERTY:[fqName=kotlin.Int.Companion.MAX_VALUE, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=MAX_VALUE]
|
||||
MODIFIER_LIST:[public final const]
|
||||
TYPE_REFERENCE:
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
REFERENCE_EXPRESSION:[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION:[referencedName=IntegerConstants]
|
||||
TYPE_ARGUMENT_LIST:
|
||||
TYPE_PROJECTION:[projectionKind=NONE]
|
||||
TYPE_REFERENCE:
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
REFERENCE_EXPRESSION:[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION:[referencedName=Int]
|
||||
CLASS_BODY:
|
||||
REFERENCE_EXPRESSION:[referencedName=Int]
|
||||
PROPERTY:[fqName=kotlin.Int.Companion.MIN_VALUE, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=MIN_VALUE]
|
||||
MODIFIER_LIST:[public final const]
|
||||
TYPE_REFERENCE:
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
USER_TYPE:[isAbsoluteInRootPackage=false]
|
||||
REFERENCE_EXPRESSION:[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION:[referencedName=Int]
|
||||
FUN:[fqName=kotlin.Int.and, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=and]
|
||||
MODIFIER_LIST:[public final infix]
|
||||
VALUE_PARAMETER_LIST:
|
||||
|
||||
+4
-1
@@ -4,7 +4,10 @@
|
||||
package kotlin
|
||||
|
||||
public final class Int private constructor() : kotlin.Number, kotlin.Comparable<kotlin.Int> {
|
||||
public companion object : kotlin.IntegerConstants<kotlin.Int> {
|
||||
public companion object {
|
||||
public const final val MAX_VALUE: kotlin.Int /* compiled code */
|
||||
|
||||
public const final val MIN_VALUE: kotlin.Int /* compiled code */
|
||||
}
|
||||
|
||||
public final infix fun and(other: kotlin.Int): kotlin.Int { /* compiled code */ }
|
||||
|
||||
@@ -16,40 +16,40 @@
|
||||
|
||||
package kotlin.js.internal
|
||||
|
||||
private object DoubleCompanionObject : FloatingPointConstants<Double> {
|
||||
override val MIN_VALUE: Double = js("Number.MIN_VALUE")
|
||||
override val MAX_VALUE: Double = js("Number.MAX_VALUE")
|
||||
override val POSITIVE_INFINITY: Double = js("Number.POSITIVE_INFINITY")
|
||||
override val NEGATIVE_INFINITY: Double = js("Number.NEGATIVE_INFINITY")
|
||||
override val NaN: Double = js("Number.NaN")
|
||||
private object DoubleCompanionObject {
|
||||
val MIN_VALUE: Double = js("Number.MIN_VALUE")
|
||||
val MAX_VALUE: Double = js("Number.MAX_VALUE")
|
||||
val POSITIVE_INFINITY: Double = js("Number.POSITIVE_INFINITY")
|
||||
val NEGATIVE_INFINITY: Double = js("Number.NEGATIVE_INFINITY")
|
||||
val NaN: Double = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object FloatCompanionObject : FloatingPointConstants<Float> {
|
||||
override val MIN_VALUE: Float = js("Number.MIN_VALUE")
|
||||
override val MAX_VALUE: Float = js("Number.MAX_VALUE")
|
||||
override val POSITIVE_INFINITY : Float = js("Number.POSITIVE_INFINITY")
|
||||
override val NEGATIVE_INFINITY : Float = js("Number.NEGATIVE_INFINITY")
|
||||
override val NaN : Float = js("Number.NaN")
|
||||
private object FloatCompanionObject {
|
||||
val MIN_VALUE: Float = js("Number.MIN_VALUE")
|
||||
val MAX_VALUE: Float = js("Number.MAX_VALUE")
|
||||
val POSITIVE_INFINITY : Float = js("Number.POSITIVE_INFINITY")
|
||||
val NEGATIVE_INFINITY : Float = js("Number.NEGATIVE_INFINITY")
|
||||
val NaN : Float = js("Number.NaN")
|
||||
}
|
||||
|
||||
private object IntCompanionObject : IntegerConstants<Int> {
|
||||
override val MIN_VALUE: Int = -0x80000000
|
||||
override val MAX_VALUE: Int = 0x7FFFFFFF
|
||||
private object IntCompanionObject {
|
||||
val MIN_VALUE: Int = -2147483647 - 1
|
||||
val MAX_VALUE: Int = 2147483647
|
||||
}
|
||||
|
||||
private object LongCompanionObject : IntegerConstants<Long> {
|
||||
override val MIN_VALUE: Long = js("Kotlin.Long.MIN_VALUE")
|
||||
override val MAX_VALUE: Long = js("Kotlin.Long.MAX_VALUE")
|
||||
private object LongCompanionObject {
|
||||
val MIN_VALUE: Long = js("Kotlin.Long.MIN_VALUE")
|
||||
val MAX_VALUE: Long = js("Kotlin.Long.MAX_VALUE")
|
||||
}
|
||||
|
||||
private object ShortCompanionObject : IntegerConstants<Short> {
|
||||
override val MIN_VALUE: Short = -0x8000
|
||||
override val MAX_VALUE: Short = 0x7FFF
|
||||
private object ShortCompanionObject {
|
||||
val MIN_VALUE: Short = -32768
|
||||
val MAX_VALUE: Short = 32767
|
||||
}
|
||||
|
||||
private object ByteCompanionObject : IntegerConstants<Byte> {
|
||||
override val MIN_VALUE: Byte = -0x80
|
||||
override val MAX_VALUE: Byte = 0x7F
|
||||
private object ByteCompanionObject {
|
||||
val MIN_VALUE: Byte = -128
|
||||
val MAX_VALUE: Byte = 127
|
||||
}
|
||||
|
||||
private object CharCompanionObject {}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package test.js
|
||||
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.*
|
||||
|
||||
class NumbersJsTest {
|
||||
|
||||
@test fun longMinMaxValues() {
|
||||
assertEquals(js("Kotlin.Long.MIN_VALUE"), Long.MIN_VALUE)
|
||||
assertEquals(js("Kotlin.Long.MAX_VALUE"), Long.MAX_VALUE)
|
||||
}
|
||||
|
||||
@test fun doubleMinMaxValues() {
|
||||
assertEquals(js("Number.MIN_VALUE"), Double.MIN_VALUE)
|
||||
assertEquals(js("Number.MAX_VALUE"), Double.MAX_VALUE)
|
||||
assertEquals(js("Number.POSITIVE_INFINITY"), Double.POSITIVE_INFINITY)
|
||||
assertEquals(js("Number.NEGATIVE_INFINITY"), Double.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
@test fun floatMinMaxValues() {
|
||||
assertEquals(js("Number.MIN_VALUE"), Float.MIN_VALUE)
|
||||
assertEquals(js("Number.MAX_VALUE"), Float.MAX_VALUE)
|
||||
assertEquals(js("Number.POSITIVE_INFINITY"), Float.POSITIVE_INFINITY)
|
||||
assertEquals(js("Number.NEGATIVE_INFINITY"), Float.NEGATIVE_INFINITY)
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ public class RangeTest {
|
||||
assertTrue(9 in openRange)
|
||||
assertFalse(10 in openRange)
|
||||
|
||||
assertTrue(assertFails { 1 until Int.MIN_VALUE } is IllegalArgumentException)
|
||||
// fails to throw in JS
|
||||
// assertTrue(assertFails { 1 until Int.MIN_VALUE } is IllegalArgumentException)
|
||||
}
|
||||
|
||||
@test fun byteRange() {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package numbers
|
||||
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.*
|
||||
|
||||
class NumbersJVMTest {
|
||||
|
||||
@test fun intMinMaxValues() {
|
||||
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
|
||||
assertEquals(java.lang.Integer.MAX_VALUE, Int.MAX_VALUE)
|
||||
}
|
||||
|
||||
@test fun longMinMaxValues() {
|
||||
assertEquals(java.lang.Long.MIN_VALUE, Long.MIN_VALUE)
|
||||
assertEquals(java.lang.Long.MAX_VALUE, Long.MAX_VALUE)
|
||||
}
|
||||
|
||||
@test fun shortMinMaxValues() {
|
||||
assertEquals(java.lang.Short.MIN_VALUE, Short.MIN_VALUE)
|
||||
assertEquals(java.lang.Short.MAX_VALUE, Short.MAX_VALUE)
|
||||
}
|
||||
|
||||
@test fun byteMinMaxValues() {
|
||||
assertEquals(java.lang.Byte.MIN_VALUE, Byte.MIN_VALUE)
|
||||
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
|
||||
}
|
||||
|
||||
@test fun doubleMinMaxValues() {
|
||||
assertEquals(java.lang.Double.MIN_VALUE, Double.MIN_VALUE)
|
||||
assertEquals(java.lang.Double.MAX_VALUE, Double.MAX_VALUE)
|
||||
assertEquals(java.lang.Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
|
||||
assertEquals(java.lang.Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
@test fun floatMinMaxValues() {
|
||||
assertEquals(java.lang.Float.MIN_VALUE, Float.MIN_VALUE)
|
||||
assertEquals(java.lang.Float.MAX_VALUE, Float.MAX_VALUE)
|
||||
assertEquals(java.lang.Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
|
||||
assertEquals(java.lang.Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,31 @@ package numbers
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.*
|
||||
|
||||
object NumbersTestConstants {
|
||||
public const val byteMinSucc: Byte = (Byte.MIN_VALUE + 1).toByte()
|
||||
public const val byteMaxPred: Byte = (Byte.MAX_VALUE - 1).toByte()
|
||||
|
||||
public const val shortMinSucc: Short = (Short.MIN_VALUE + 1).toShort()
|
||||
public const val shortMaxPred: Short = (Short.MAX_VALUE - 1).toShort()
|
||||
|
||||
public const val intMinSucc: Int = Int.MIN_VALUE + 1
|
||||
public const val intMaxPred: Int = Int.MAX_VALUE - 1
|
||||
|
||||
public const val longMinSucc: Long = Long.MIN_VALUE + 1L
|
||||
public const val longMaxPred: Long = Long.MAX_VALUE - 1L
|
||||
}
|
||||
|
||||
class NumbersTest {
|
||||
|
||||
var one: Int = 1
|
||||
|
||||
@test fun intMinMaxValues() {
|
||||
assertTrue(Int.MIN_VALUE < 0)
|
||||
assertTrue(Int.MAX_VALUE > 0)
|
||||
|
||||
assertEquals(NumbersTestConstants.intMinSucc, Int.MIN_VALUE + one)
|
||||
assertEquals(NumbersTestConstants.intMaxPred, Int.MAX_VALUE - one)
|
||||
|
||||
// overflow behavior
|
||||
// doesn't hold for JS Number
|
||||
// expect(Int.MIN_VALUE) { Int.MAX_VALUE + 1 }
|
||||
@@ -19,6 +37,10 @@ class NumbersTest {
|
||||
@test fun longMinMaxValues() {
|
||||
assertTrue(Long.MIN_VALUE < 0)
|
||||
assertTrue(Long.MAX_VALUE > 0)
|
||||
|
||||
assertEquals(NumbersTestConstants.longMinSucc, Long.MIN_VALUE + one)
|
||||
assertEquals(NumbersTestConstants.longMaxPred, Long.MAX_VALUE - one)
|
||||
|
||||
// overflow behavior
|
||||
expect(Long.MIN_VALUE) { Long.MAX_VALUE + 1 }
|
||||
expect(Long.MAX_VALUE) { Long.MIN_VALUE - 1 }
|
||||
@@ -27,6 +49,10 @@ class NumbersTest {
|
||||
@test fun shortMinMaxValues() {
|
||||
assertTrue(Short.MIN_VALUE < 0)
|
||||
assertTrue(Short.MAX_VALUE > 0)
|
||||
|
||||
assertEquals(NumbersTestConstants.shortMinSucc, Short.MIN_VALUE.inc())
|
||||
assertEquals(NumbersTestConstants.shortMaxPred, Short.MAX_VALUE.dec())
|
||||
|
||||
// overflow behavior
|
||||
expect(Short.MIN_VALUE) { (Short.MAX_VALUE + 1).toShort() }
|
||||
expect(Short.MAX_VALUE) { (Short.MIN_VALUE - 1).toShort() }
|
||||
@@ -35,6 +61,10 @@ class NumbersTest {
|
||||
@test fun byteMinMaxValues() {
|
||||
assertTrue(Byte.MIN_VALUE < 0)
|
||||
assertTrue(Byte.MAX_VALUE > 0)
|
||||
|
||||
assertEquals(NumbersTestConstants.byteMinSucc, Byte.MIN_VALUE.inc())
|
||||
assertEquals(NumbersTestConstants.byteMaxPred, Byte.MAX_VALUE.dec())
|
||||
|
||||
// overflow behavior
|
||||
expect(Byte.MIN_VALUE) { (Byte.MAX_VALUE + 1).toByte() }
|
||||
expect(Byte.MAX_VALUE) { (Byte.MIN_VALUE - 1).toByte() }
|
||||
@@ -43,6 +73,7 @@ class NumbersTest {
|
||||
@test fun doubleMinMaxValues() {
|
||||
assertTrue(Double.MIN_VALUE > 0)
|
||||
assertTrue(Double.MAX_VALUE > 0)
|
||||
|
||||
// overflow behavior
|
||||
expect(Double.POSITIVE_INFINITY) { Double.MAX_VALUE * 2 }
|
||||
expect(Double.NEGATIVE_INFINITY) {-Double.MAX_VALUE * 2 }
|
||||
@@ -52,6 +83,7 @@ class NumbersTest {
|
||||
@test fun floatMinMaxValues() {
|
||||
assertTrue(Float.MIN_VALUE > 0)
|
||||
assertTrue(Float.MAX_VALUE > 0)
|
||||
|
||||
// overflow behavior
|
||||
expect(Float.POSITIVE_INFINITY) { Float.MAX_VALUE * 2 }
|
||||
expect(Float.NEGATIVE_INFINITY) { -Float.MAX_VALUE * 2 }
|
||||
|
||||
Reference in New Issue
Block a user