[FIR] Add test data

This commit is contained in:
Nikolay Lunyak
2021-08-09 16:02:09 +03:00
committed by TeamCityServer
parent 4e56ba2fa4
commit f6ae6af741
69 changed files with 1834 additions and 27 deletions
@@ -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()
}
}
@@ -0,0 +1,8 @@
class Base {
val x: CharSequence
internal field: String = "OK"
}
fun box(): String {
return Base().x
}
@@ -0,0 +1,10 @@
class Base {
val x: CharSequence
internal field: String = "OK"
val s: String get() = x
}
fun box(): String {
return Base().s
}
@@ -0,0 +1,9 @@
class Base {
val x: CharSequence
internal field: String = "OK"
}
val s: String get() = Base().x
fun box(): String {
return s
}
@@ -0,0 +1,9 @@
class Base {
val x: CharSequence
internal field: String = "OK"
}
val s: String = Base().x
fun box(): String {
return s
}
@@ -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
}
@@ -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"
}
}
@@ -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
}
@@ -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"
}
@@ -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"
}
}
@@ -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()
}