[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,51 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun getBoolean(): Boolean = false
fun test() {
val x: Int
if (getBoolean())
myRun {
while (getBoolean()) {
do {
myRun {
if (getBoolean()) {
x = 42 // No reassignment because of break
}
else {
x = 43 // No reassignment because of break
}
}
break
} while (getBoolean())
// Loop executed exectly once, initializing x
myRun { x.inc() }
myRun { x = 42 }
break
}
// x is I?D here because loop could've been execited
// VAL_REASSIGNMENT isn't reported because of repeating diagnostic
x = 42
// x is ID now
}
else
myRun {
x = 42
}
// x is ID because both branches are ID
x.inc()
}
@@ -0,0 +1,18 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun functionWithExpressionBody(x: Int): Boolean = myRun {
if (x == 0) return true
if (x == 1) return false
return functionWithExpressionBody(x - 2)
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun functionWithSideEffects(x: Int): Int = x + 1 // ...and some other useful side-effects
fun log(s: String) = Unit // some logging or println or whatever returning Unit
fun implicitCastWithIf(s: String) {
myRun { if (s == "") functionWithSideEffects(42) else log(s) }
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun myRun(block: () -> Unit): Unit {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
block()
}
fun test() {
myRun { throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalArgumentException<!>() }
val x: Int = 42
}
@@ -0,0 +1,23 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun myRun(block: () -> Unit): Unit {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
inline fun unknownRun(block: () -> Unit) { block() }
fun foo() {
val x: Int
myRun {
unknownRun { println("shouldn't change anything") }
x = 42
}
println(x)
}
@@ -0,0 +1,86 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
inline fun <T, R> T.myLet(block: (T) -> R): R {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block(this)
}
inline fun unknownRun(block: () -> Unit) = block()
fun getBool(): Boolean = false
fun threeLevelsReturnNoInitialization(x: Int?): Int? {
// Inner always jumps to outer
// And middle always calls inner
// So, in fact, middle never finished normally
// Hence 'y = 54' in middle is unreachable, and middle doesn't performs definite initialization
// Hence, outer doesn't performs definite initialization
val y: Int
myRun outer@ {
myRun middle@ {
x.myLet inner@ {
if (it == null) {
y = 42
return@outer Unit
}
else {
return@outer Unit
}
}
}
// Possible to report unreachable here
y = 54
}
return y.inc()
}
fun threeLevelsReturnWithInitialization(x: Int?): Int? {
val y: Int
myRun outer@ {
myRun middle@ {
x.myLet inner@ {
if (it == null) {
y = 42
return@outer Unit
}
else {
y = 34
return@outer Unit
}
}
}
}
return y.inc()
}
fun threeLevelsReturnWithUnknown(x: Int?): Int? {
val y: Int
myRun outer@ {
unknownRun middle@ {
x.myLet inner@ {
if (it == null) {
y = 42
return@outer Unit
}
else {
y = 34
return@outer Unit
}
}
}
}
return y.inc()
}
@@ -0,0 +1,98 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -INVISIBLE_MEMBER -INVISIBLE_REFERENCE
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun innerComputation(): Int = 42
fun outerComputation(): Int = 52
fun log() = Unit
fun outerFinallyInitializes() {
val x: Int
try {
myRun {
try {
x = innerComputation()
} catch (e: java.lang.Exception) {
log()
}
// possible reassignment if innerComputation finished
x = 42
// x is ID here
}
// Definite reassignment here, cause can get here only if myRun finished
// Not reported because of repeating diagnostic
x = outerComputation()
} catch (e: java.lang.Exception) {
// can catch exception thrown by the inner, so x can be not initialized
x.inc()
log()
} finally {
// Possible reassignment (e.g. if everything finished)
// Not reported because of repeating diagnostic
x = 42
}
// Properly initialized
x.inc()
}
fun innerFinallyInitializes() {
val x: Int
try {
myRun {
try {
innerComputation()
} catch (e: java.lang.Exception) {
log()
} finally {
x = 42
}
}
// Properly initialized
x.inc()
} catch (e: java.lang.Exception) {
log()
}
// Still can be unitialized because we don't know what can happen in try-block
// (e.g., OutOfMemory exception could've happened even before myRun was executed)
x.inc()
}
fun innerFinallyInitializesOuterRethrows() {
val x: Int
try {
myRun {
try {
innerComputation()
} catch (e: java.lang.Exception) {
log()
} finally {
x = 42
}
}
// Properly initialized
x.inc()
} catch (e: java.lang.Exception) {
log()
throw e
}
// Guaranteed to be initialized because all catch-clauses are rethrowing
x.inc()
}
@@ -0,0 +1,47 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun innerComputation(): Int = 42
fun outerComputation(): Int = 52
fun innerTryCatchInitializes() {
val x: Int
try {
myRun {
try {
x = innerComputation()
x.inc()
}
catch (e: java.lang.Exception) {
// Potential reassignment because x.inc() could threw
x = 42
x.inc()
}
}
// Can get here only when inlined lambda exited properly, i.e. x is initialized
x.inc()
outerComputation()
} catch (e: java.lang.Exception) {
// Can get here if innerComputation() threw an exception that wasn't catched by the inner catch (x is not initialized)
// OR if outerComputation() threw an exception (x is initialized because we reach outer computation only when inner finished ok)
// So, x=I? here
x.inc()
// Potential reasignment
x = 42
}
// Here x=I because outer try-catch either exited normally (x=I) or catched exception (x=I, with reassingment, though)
x.inc()
}
@@ -0,0 +1,18 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T, R> T.myLet(block: (T) -> R): R {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block(this)
}
fun nonLocalReturnWithElvis(x: Int?): Int? {
x?.myLet { return 42 }
return x?.inc()
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun myRun(block: () -> Unit): Unit {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun getBool(): Boolean = false
fun withLabeledReturn() {
val y: Int
val x = myRun outer@ {
myRun { return@outer Unit }
y = 42
}
println(y)
println(x)
}
fun withLabeledReturn2(y: Int) {
myRun outer@ {
myRun { return@outer Unit }
println(y)
}
println(y)
}
@@ -0,0 +1,23 @@
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> Any?.myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun bad(): String {
val x: String? = null
x?.myRun { return "" }
}
fun ok(): String {
val x: String? = null
x?.run { return "non-null" } ?: return "null"
}
@@ -0,0 +1,79 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun exitOnlyThroughLocalReturns(b: Boolean) {
var x: Int
var s: String
myRun {
if (b) {
x = 42
return@myRun
}
if (!b) {
s = "hello"
x = 42
return@myRun
}
else {
s = "world"
x = 239
}
}
x.inc()
s.length
}
fun exitOnlyThroughNonLocalReturns(b: Boolean?) {
var x: Int
var s: String
myRun {
if (b == null) {
x = 42
return
}
if (b.not()) {
x = 54
}
if (x == 42) {
return
}
else {
x = 42
s = "hello"
return
}
}
x.inc()
s.length
}
fun nonLocalReturnAndOrdinaryExit(b: Boolean) {
var x: Int
var s: String
myRun {
if (b) {
x = 42
return
}
x = 54
s = "hello"
}
x.inc()
s.length
}
@@ -0,0 +1,48 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun myRun(block: () -> Unit) {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
block()
}
inline fun <T> unknownRun(block: () -> T): T = block()
fun throwIfNotCalled() {
val x: Int
myRun outer@ {
unknownRun {
myRun {
x = 42
return@outer
}
}
throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalArgumentException<!>()
}
// x *is* initialized here, because if myRun was never called -> exception
// were thrown and control flow wouldn't be here
println(x)
}
fun catchThrowIfNotCalled() {
val x: Int
try {
myRun outer@ {
unknownRun {
myRun {
x = 42
return@outer
}
}
throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalArgumentException<!>()
}
} catch (ignored: java.lang.IllegalArgumentException) { }
// x *isn't* initialized here!
println(x)
}
@@ -0,0 +1,58 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun someComputation(): Int = 42
fun tryCatchInlined() {
val x: Int
myRun {
try {
x = someComputation()
x.inc()
}
catch (e: java.lang.Exception) {
x.inc()
}
}
x = 42
x.inc()
}
fun possibleReassignmentInTryCatch() {
val x: Int
myRun {
try {
x = someComputation()
x.inc()
}
catch (e: java.lang.Exception) {
x = 42
x.inc()
}
x.inc()
}
x.inc()
}
fun tryCatchOuter() {
val x: Int
try {
myRun { x = someComputation() }
x.inc()
}
catch (e: java.lang.Exception) {
x.inc()
}
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_PARAMETER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun someComputation(): Int = 42
fun report(x: Int) = Unit
fun innerTryCatchFinally() {
val x: Int
myRun {
try {
x = someComputation()
report(x)
} catch (e: java.lang.Exception) {
x = 42
report(x)
} finally {
x = 0
}
}
x.inc()
}
@@ -0,0 +1,19 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun foo(x: Int): Int = x + 1
fun typeMismatchInLambda(y: String): Int {
val x = myRun { <!INAPPLICABLE_CANDIDATE!>foo<!>(y) }
return x
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
inline fun <T> myRun(block: () -> T): T {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
fun throwInLambda(): Int {
val x = myRun { throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalArgumentException<!>(); 42 }
return x
}