[FIR] Add test data
This commit is contained in:
committed by
TeamCityServer
parent
4e56ba2fa4
commit
f6ae6af741
+15
@@ -0,0 +1,15 @@
|
||||
class A {
|
||||
val a: Number
|
||||
private field = 1
|
||||
|
||||
val b: Number
|
||||
internal field = a + 3
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (A().b + 20 == 24) {
|
||||
"OK"
|
||||
} else {
|
||||
"fail: A().b = " + A().b.toString()
|
||||
}
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
class Base {
|
||||
val x: CharSequence
|
||||
internal field: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Base().x
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
class Base {
|
||||
val x: CharSequence
|
||||
internal field: String = "OK"
|
||||
|
||||
val s: String get() = x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Base().s
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class Base {
|
||||
val x: CharSequence
|
||||
internal field: String = "OK"
|
||||
|
||||
}
|
||||
val s: String get() = Base().x
|
||||
fun box(): String {
|
||||
return s
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class Base {
|
||||
val x: CharSequence
|
||||
internal field: String = "OK"
|
||||
|
||||
}
|
||||
val s: String = Base().x
|
||||
fun box(): String {
|
||||
return s
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
open class Base {
|
||||
open val x: CharSequence = "BASE"
|
||||
// field = "BASE"
|
||||
}
|
||||
|
||||
class Ok : Base() {
|
||||
override val x: CharSequence
|
||||
internal field: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Ok().x
|
||||
}
|
||||
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
interface I {
|
||||
val number: Number
|
||||
}
|
||||
|
||||
fun test1(): String? {
|
||||
val it = object : I {
|
||||
final override val number: Number
|
||||
field = 10
|
||||
|
||||
val next get() = number + 1
|
||||
}
|
||||
|
||||
return if (it.next != 11) {
|
||||
"[1] ${it.number}, ${it.next}"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): String? {
|
||||
class Local : I {
|
||||
final override val number: Number
|
||||
internal field = 42
|
||||
}
|
||||
|
||||
return if (Local().number + 3 != 45) {
|
||||
"[2] " + Local().number.toString()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(): String? {
|
||||
val it = object : I {
|
||||
override val number: Number
|
||||
field = "100"
|
||||
get() {
|
||||
return field.length
|
||||
}
|
||||
}
|
||||
|
||||
return if (it.number != 3) {
|
||||
"[3] " + it.number.toString()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val problem = test1()
|
||||
?: test2()
|
||||
?: test3()
|
||||
|
||||
return if (problem != null) {
|
||||
"fail: " + problem
|
||||
} else {
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
compiler/fir/fir2ir/testData/codegen/box/properties/backingField/getterReturnTypeWithBackingField.kt
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
interface Storage {
|
||||
val s: String
|
||||
}
|
||||
|
||||
class ImmutableStorage(override val s: String) : Storage
|
||||
class MutableStorage(override var s: String) : Storage {
|
||||
fun asImmutable() = ImmutableStorage(s)
|
||||
}
|
||||
|
||||
class My {
|
||||
val storage: Storage
|
||||
field = MutableStorage("OK")
|
||||
get() = field.asImmutable()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val my = My()
|
||||
if (my.storage is MutableStorage) {
|
||||
return "MUTABLE"
|
||||
}
|
||||
return my.storage.s
|
||||
}
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
fun createString() = "AAA" + "BBB"
|
||||
|
||||
class A {
|
||||
var it: Int
|
||||
field = 3.14
|
||||
get() = (field + 10).toInt()
|
||||
set(value) {
|
||||
field = (value - 10).toDouble()
|
||||
|
||||
if (field < -3 || -1 < field) {
|
||||
throw Exception("fail: value = $value, field = $field")
|
||||
}
|
||||
}
|
||||
|
||||
var that: Int
|
||||
field = createString() + "!"
|
||||
get() = field.length
|
||||
set(value) {
|
||||
field = value.toString()
|
||||
|
||||
if (field != "17") {
|
||||
throw Exception("fail: value = $value, field = $field")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val a = A()
|
||||
|
||||
val it: Int = A().it and 10
|
||||
a.it = it
|
||||
|
||||
val that: Int = a.that
|
||||
a.that = that + 10
|
||||
} catch (e: Exception) {
|
||||
return e.message ?: "fail"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
var that: Int
|
||||
lateinit field: String
|
||||
get() = field.length
|
||||
set(value) {
|
||||
field = value.toString()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
that = 1
|
||||
|
||||
return if (that == 1) {
|
||||
"OK"
|
||||
} else {
|
||||
"fail: $that"
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
open class A {
|
||||
open var it: Number
|
||||
private field = 3
|
||||
set(value) {
|
||||
field = value.toInt()
|
||||
}
|
||||
|
||||
fun test(): String {
|
||||
// Note that `it` is open,
|
||||
// so no smart type narrowing
|
||||
// is possible, and we expect
|
||||
// here a call to the possibly
|
||||
// overridden getter
|
||||
return if (it.toInt() + 1 == 11) {
|
||||
"OK"
|
||||
} else {
|
||||
"fail: $it"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
override var it: Number
|
||||
get() = 10.12
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return B().test()
|
||||
}
|
||||
Reference in New Issue
Block a user