[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
class My(val x: Int) {
|
||||
val y: Int = x + 3
|
||||
val z: Int? = foo()
|
||||
|
||||
fun foo() = if (x >= 0) x else if (y >= 0) y else null
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
fun foo() = 42
|
||||
|
||||
class Your {
|
||||
fun bar() = 13
|
||||
}
|
||||
|
||||
class My {
|
||||
val your = Your()
|
||||
|
||||
val x = foo()
|
||||
|
||||
val y = Your().bar()
|
||||
|
||||
val z = your.bar()
|
||||
|
||||
// This extension function also can use our properties,
|
||||
// so the call is also dangerous
|
||||
val w = your.gav()
|
||||
|
||||
val v = Your().gav()
|
||||
|
||||
val t = your.other()
|
||||
|
||||
val r = Your().other()
|
||||
|
||||
fun Your.gav() = if (your.bar() == 0) t else r
|
||||
}
|
||||
|
||||
fun Your.other() = "3"
|
||||
@@ -0,0 +1,11 @@
|
||||
class My {
|
||||
val x: String
|
||||
|
||||
constructor() {
|
||||
val temp = this
|
||||
x = bar(temp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun bar(arg: My) = arg.x
|
||||
@@ -0,0 +1,30 @@
|
||||
class My {
|
||||
var x = 1
|
||||
set(value) {
|
||||
field = value
|
||||
}
|
||||
|
||||
var y: Int = 1
|
||||
set(value) {
|
||||
field = value + if (w == "") 0 else 1
|
||||
}
|
||||
|
||||
var z: Int = 2
|
||||
set(value) {
|
||||
field = value + if (w == "") 1 else 0
|
||||
}
|
||||
|
||||
var m: Int = 2
|
||||
set
|
||||
|
||||
init {
|
||||
x = 3
|
||||
m = 6
|
||||
|
||||
// Writing properties using setters is dangerous
|
||||
y = 4
|
||||
this.z = 5
|
||||
}
|
||||
|
||||
val w = "6"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class My {
|
||||
val x: String
|
||||
|
||||
constructor() {
|
||||
val y = bar(this)
|
||||
val z = foo()
|
||||
x = "$y$z"
|
||||
}
|
||||
|
||||
fun foo() = x
|
||||
}
|
||||
|
||||
fun bar(arg: My) = arg.x
|
||||
@@ -0,0 +1,19 @@
|
||||
class My {
|
||||
|
||||
val x = foo()
|
||||
|
||||
val w = bar()
|
||||
|
||||
fun foo() = 0
|
||||
|
||||
companion object {
|
||||
|
||||
val y = <!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
|
||||
val u = bar()
|
||||
|
||||
val z: String? = bar()
|
||||
|
||||
fun bar() = "1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
val instance = My()
|
||||
|
||||
class My {
|
||||
val equalsInstance = (this == instance)
|
||||
|
||||
val isInstance = if (this === instance) "true" else "false"
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is My && isInstance.hashCode() == other.isInstance.hashCode()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate(val x: Int) {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = x
|
||||
}
|
||||
|
||||
class My {
|
||||
val x: Int by Delegate(this.foo())
|
||||
|
||||
fun foo(): Int = x
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
open class Base(val x: String) {
|
||||
fun foo() = bar()
|
||||
|
||||
open fun bar() = -1
|
||||
}
|
||||
|
||||
class Derived(x: String): Base(x) {
|
||||
// It's still dangerous: we're not sure that foo() does not call some open function inside
|
||||
val y = foo()
|
||||
val z = x
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface Base {
|
||||
val x: Int
|
||||
}
|
||||
|
||||
open class Impl(override val x: Int) : Base {
|
||||
init {
|
||||
if (this.x != 0) foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,26 @@
|
||||
class My(var x: String) {
|
||||
|
||||
var y: String
|
||||
get() = if (x != "") x else z
|
||||
set(arg) {
|
||||
if (arg != "") x = arg
|
||||
}
|
||||
|
||||
val z: String
|
||||
|
||||
var d: String = ""
|
||||
get
|
||||
set
|
||||
|
||||
val z1: String
|
||||
|
||||
init {
|
||||
d = "d"
|
||||
if (d != "") z1 = this.d else z1 = d
|
||||
|
||||
// Dangerous: setter!
|
||||
y = "x"
|
||||
// Dangerous: getter!
|
||||
if (y != "") z = this.y else z = y
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class My {
|
||||
val x: String
|
||||
|
||||
init {
|
||||
x = foo()
|
||||
}
|
||||
|
||||
fun foo(): String = x
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
|
||||
private const val A = 0L
|
||||
private val B = 0L
|
||||
private fun sample() = 0L
|
||||
|
||||
private class PrivateClass
|
||||
|
||||
class Foo {
|
||||
var bar: Long = 0
|
||||
private var other: PrivateClass? = null
|
||||
|
||||
init {
|
||||
bar = A
|
||||
bar = B
|
||||
bar = sample()
|
||||
other = PrivateClass()
|
||||
}
|
||||
|
||||
constructor()
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class My {
|
||||
val x: Int
|
||||
get() = field + if (z != "") 1 else 0
|
||||
|
||||
val y: Int
|
||||
get() = field - if (z == "") 0 else 1
|
||||
|
||||
val w: Int
|
||||
|
||||
init {
|
||||
// Safe, val never has a setter
|
||||
x = 0
|
||||
this.y = 0
|
||||
// Unsafe
|
||||
w = this.x + y
|
||||
}
|
||||
|
||||
val z = "1"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
class First {
|
||||
val x: String
|
||||
|
||||
init {
|
||||
use(this) // NPE! Leaking this
|
||||
x = foo() // NPE! Own function
|
||||
}
|
||||
|
||||
fun foo() = x
|
||||
}
|
||||
|
||||
fun use(first: First) = first.x.hashCode()
|
||||
|
||||
abstract class Second {
|
||||
val x: String
|
||||
|
||||
init {
|
||||
use(this) // Leaking this in non-final
|
||||
x = bar() // Own function in non-final
|
||||
foo() // Non-final function call
|
||||
}
|
||||
|
||||
private fun bar() = foo()
|
||||
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
fun use(second: Second) = second.x
|
||||
|
||||
class SecondDerived : Second() {
|
||||
val y = x // null!
|
||||
|
||||
override fun foo() = y
|
||||
}
|
||||
|
||||
open class Third {
|
||||
open var x: String
|
||||
|
||||
constructor() {
|
||||
x = "X" // Non-final property access
|
||||
}
|
||||
}
|
||||
|
||||
class ThirdDerived : Third() {
|
||||
override var x: String = "Y"
|
||||
set(arg) { field = "$arg$y" }
|
||||
|
||||
val y = ""
|
||||
}
|
||||
|
||||
class Fourth {
|
||||
val x: String
|
||||
get() = y
|
||||
|
||||
val y = x // null!
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface Wise {
|
||||
fun doIt(): Int
|
||||
}
|
||||
|
||||
fun Wise(f: () -> Int) = object: Wise {
|
||||
override fun doIt() = f()
|
||||
}
|
||||
|
||||
class My {
|
||||
// Still dangerous (???), nobogy can guarantee what Wise() will do with this lambda
|
||||
val x = Wise { foo() }
|
||||
|
||||
val y = 42
|
||||
|
||||
fun foo() = y
|
||||
|
||||
fun bar() = x.doIt()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class WithLateInit {
|
||||
lateinit var x: String
|
||||
|
||||
fun init(xx: String) {
|
||||
x = xx
|
||||
}
|
||||
|
||||
init {
|
||||
// This is obviously a bug,
|
||||
// but with lateinit we explicitly want it to occur in runtime
|
||||
use()
|
||||
}
|
||||
|
||||
fun use() = x
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
open class Wise {
|
||||
|
||||
val x = 1
|
||||
|
||||
open fun doIt(): Int = 42
|
||||
}
|
||||
|
||||
class My {
|
||||
|
||||
fun foo(): Int {
|
||||
val wise = object: Wise() {
|
||||
var xx = 1
|
||||
override fun doIt() = super.doIt() + bar(this) + xx
|
||||
}
|
||||
return wise.doIt()
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(wise: Wise): Int = wise.x
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Context
|
||||
class Point
|
||||
|
||||
class Example {
|
||||
constructor(context: Context?)
|
||||
constructor(context: Context?, arg1: Int)
|
||||
constructor(context: Context?, arg1: Int, arg2: Int)
|
||||
constructor(context: Context?, arg1: Int, arg2: Int, arg3: Int)
|
||||
|
||||
var condition: Boolean = false
|
||||
private var index = newIndex(condition)
|
||||
private fun newIndex(zero: Boolean) = if (zero) 0 else 1
|
||||
|
||||
private lateinit var latePoint1: Point
|
||||
private lateinit var latePoint2: Point
|
||||
|
||||
private val point1 = Point()
|
||||
private val point2 = Point()
|
||||
private val point3 = Point()
|
||||
private val point4 = Point()
|
||||
private var nullPoint: Point? = null
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class My {
|
||||
|
||||
val x: Int
|
||||
get() = 1
|
||||
|
||||
init {
|
||||
// x has no backing field, so the call is safe
|
||||
foo()
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
open class Base {
|
||||
init {
|
||||
register(this)
|
||||
foo()
|
||||
}
|
||||
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
fun register(arg: Base) {
|
||||
arg.foo()
|
||||
}
|
||||
|
||||
class Derived(val x: Int) : Base() {
|
||||
override fun foo() {
|
||||
x.hashCode() // NPE in Base constructor
|
||||
}
|
||||
}
|
||||
|
||||
enum class MyEnum {
|
||||
FIRST() {
|
||||
val x: Int = 42
|
||||
|
||||
override fun foo() {
|
||||
x.hashCode() // NPE in MyEnum constructor
|
||||
}
|
||||
};
|
||||
|
||||
init {
|
||||
foo()
|
||||
}
|
||||
|
||||
abstract fun foo()
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
open class Base {
|
||||
open var x: Int
|
||||
|
||||
open var y: Int
|
||||
|
||||
constructor() {
|
||||
x = 42
|
||||
this.y = 24
|
||||
val temp = this.x
|
||||
this.x = y
|
||||
y = temp
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Outer {
|
||||
|
||||
fun foo() = 1
|
||||
|
||||
inner class Inner {
|
||||
|
||||
val x = this@Outer.foo()
|
||||
|
||||
val y = foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class My(x: String) {
|
||||
val y: String = foo(x)
|
||||
|
||||
fun foo(x: String) = "$x$y"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class My {
|
||||
val x: Int
|
||||
|
||||
constructor(x: Int) {
|
||||
this.x = x
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun use(x: Any?) = x
|
||||
|
||||
class Eap {
|
||||
private val foo = toString()
|
||||
|
||||
constructor(foo: Int) {
|
||||
use(foo)
|
||||
}
|
||||
constructor(foo: String) {
|
||||
use(foo)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user