Support secondary constructors for inline classes
#KT-25614 Fixed #KT-25246 Fixed KT-25599 Will be fixed after recompilation of unsigned classes
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
|
||||
inline class Rgba(val value: Int) {
|
||||
inline val r: Int get() = (value shr 0) and 0xFF
|
||||
inline val g: Int get() = (value shr 8) and 0xFF
|
||||
inline val b: Int get() = (value shr 16) and 0xFF
|
||||
inline val a: Int get() = (value shr 24) and 0xFF
|
||||
}
|
||||
|
||||
fun Rgba(r: Int, g: Int, b: Int, a: Int): Rgba {
|
||||
return Rgba(
|
||||
((r and 0xFF) shl 0) or ((g and 0xFF) shl 8) or ((b and 0xFF) shl 16) or ((a and 0xFF) shl 24)
|
||||
)
|
||||
}
|
||||
|
||||
fun Rgba.withR(r: Int) = Rgba(r, g, b, a)
|
||||
fun Rgba.withG(g: Int) = Rgba(r, g, b, a)
|
||||
fun Rgba.withB(b: Int) = Rgba(r, g, b, a)
|
||||
fun Rgba.withA(a: Int) = Rgba(r, g, b, a)
|
||||
|
||||
inline class RgbaArray(val array: IntArray) {
|
||||
constructor(size: Int) : this(IntArray(size))
|
||||
operator fun get(index: Int): Rgba = Rgba(array[index])
|
||||
operator fun set(index: Int, color: Rgba) {
|
||||
array[index] = color.value
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result1 = RgbaArray(32)
|
||||
val result2 = RgbaArray(IntArray(32))
|
||||
val color = Rgba(128, 128, 0, 255)
|
||||
result1[0] = color.withG(64).withA(0)
|
||||
result2[0] = color.withG(64).withA(0)
|
||||
if (result1[0].value != result2[0].value) return "Fail 1"
|
||||
if (result1[0].value != 16512) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
var global = "wrong"
|
||||
|
||||
inline class Foo(val x: String) {
|
||||
constructor(y: Int) : this(y.toString())
|
||||
constructor(z: Long) : this(z.toInt() + 1)
|
||||
constructor(other: Char) : this(other.toInt().toString()) {
|
||||
global = "OK"
|
||||
}
|
||||
constructor(a: Int, b: Int) : this((a + b).toString())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var f = Foo(42)
|
||||
if (f.x != "42") return "Fail 1: ${f.x}"
|
||||
|
||||
f = Foo(43L)
|
||||
if (f.x != "44") return "Fail 2: ${f.x}"
|
||||
|
||||
f = Foo('a')
|
||||
if (f.x != "97") return "Fail 3: ${f.x}"
|
||||
|
||||
f = Foo(1, 2)
|
||||
if (f.x != "3") return "Fail 4: ${f.x}"
|
||||
|
||||
return global
|
||||
}
|
||||
Vendored
+1
@@ -9,6 +9,7 @@ public final class Foo$Companion {
|
||||
@kotlin.Metadata
|
||||
public final static class Foo$Erased {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(p0: int): Foo
|
||||
public static method constructor(p0: int): int
|
||||
public final static method inInlineClass(p0: int): void
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
@kotlin.Metadata
|
||||
public final static class Foo$Erased {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(p0: int): Foo
|
||||
public static method constructor(p0: int): int
|
||||
public final static method getAsThis(p0: int): int
|
||||
public final static method getProp(p0: int): int
|
||||
}
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ public interface A {
|
||||
@kotlin.Metadata
|
||||
public final static class Foo$Erased {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(p0: long): Foo
|
||||
public static method constructor(p0: long): long
|
||||
public static method foo(p0: long, p1: long): void
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
@kotlin.Metadata
|
||||
public final static class Foo$Erased {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(p0: long): Foo
|
||||
public static method constructor(p0: long): long
|
||||
public final static method empty(p0: long): void
|
||||
public final static method extension(p0: long, @org.jetbrains.annotations.NotNull p1: java.lang.Object, @org.jetbrains.annotations.NotNull p2: java.lang.String): void
|
||||
public final static method param(p0: long, p1: double): void
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class AsNonNullPrimitive(val i: Int)
|
||||
inline class AsNonNullReference(val s: String) // 2 assertions (constructor, box method)
|
||||
inline class AsNonNullReference(val s: String) // 3 assertions (constructor, box method, static constructor in $Erased classs)
|
||||
|
||||
fun nonNullPrimitive(a: AsNonNullPrimitive) {}
|
||||
|
||||
@@ -11,4 +11,4 @@ fun AsNonNullReference.nonNullReferenceExtension(b1: AsNonNullReference) {} // 2
|
||||
fun asNullablePrimitive(c: AsNonNullPrimitive?) {}
|
||||
fun asNullableReference(c: AsNonNullReference?) {}
|
||||
|
||||
// 5 checkParameterIsNotNull
|
||||
// 6 checkParameterIsNotNull
|
||||
Reference in New Issue
Block a user