[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,92 @@
// !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 initialization() {
val x: Int
myRun {
x = 42
42
}
x.inc()
}
fun shadowing() {
val x = 42
myRun {
val x = 43
x.inc()
}
x.inc()
}
fun nestedDefiniteAssignment() {
val x: Int
myRun {
val y = "Hello"
myRun {
x = 42
}
y.length
}
x.inc()
}
fun deeplyNestedDefiniteAssignment() {
val x: Int
myRun {
val y: String
myRun {
val z: String
myRun {
z = "Hello"
y = "World"
x = 42
}
z.length
}
y.length
}
x.inc()
}
fun branchingFlow(a: Any?) {
val x: Int
if (a is String) {
myRun { x = 42 }
}
else {
myRun { x = 43 }
}
x.inc()
}
fun returningValue() {
val x: Int
val hello = myRun { x = 42; "hello" }
x.inc()
hello.length
}
fun unknownRun(block: () -> Unit) = block()
class DefiniteInitializationInInitSection {
val x: Int
val y: Int
init {
myRun { x = 42 }
unknownRun { y = 239 }
}
}
@@ -0,0 +1,28 @@
// !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 reassignmentInUsualFlow() {
val x: Int
myRun { x = 42 }
x = 43
x.inc()
}
fun reassignment() {
val x = 42
myRun {
x = 43
}
x.inc()
}
@@ -0,0 +1,68 @@
// !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 myRepeat(n: Int, action: () -> Unit) {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(action)
}
for (i in 1..n) action()
}
fun branchingIndetermineFlow(a: Any?) {
val x: Int
if (a is String) {
myRepeat(a.length) {
// Val reassignment because we know that repeat's lambda called in-place
myRun { x = 42 }
}
}
else {
myRun { x = 43 }
}
x.inc()
}
fun nonAnonymousLambdas() {
val x: Int
val initializer = { x = 42 }
myRun(initializer)
x.inc()
}
fun multipleAssignments() {
val x: Int
myRepeat(42) {
// Val reassignment because we know that repeat's lambda called in-place
myRun { x = 42 }
}
x.inc()
}
fun funWithUnknownInvocations(block: () -> Unit) = block()
fun nestedIndefiniteAssignment() {
val x: Int
// Captured val initialization reported, because we don't know anything about funWithUnknownInvocations
funWithUnknownInvocations { myRun { x = 42 } }
x.inc()
}
class InitializationForbiddenInNonInitSection {
val x: Int
fun setup() {
myRun { x = 42 }
}
}
@@ -0,0 +1,42 @@
// !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 definiteVarInitialization() {
var x: Int
myRun { x = 42 }
x.inc()
}
fun definiteVarReassignment() {
var x: Int
myRun { x = 42 }
x.inc()
myRun { x = 43 }
x.inc()
x = 44
x.inc()
}
fun nestedVarInitialization() {
var x: Int
myRun { myRun { myRun { x = 42 } } }
x.inc()
myRun { myRun { myRun { x = 42 } } }
}
fun notAnExpression() {
var x: Int = 0
myRun { if (true) x = 42 }
x.inc()
}
@@ -0,0 +1,51 @@
// !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 indefiniteVarReassignment(n: Int) {
var x: Int
repeat(n) {
myRun { x = 42 }
}
x.inc()
}
fun nonAnonymousLambdas() {
// Named lambdas are not inlined, even in theory it could be done for some simple cases as this one
var x: Int
val initializer = { x = 42 }
myRun(initializer)
x.inc()
}
fun branchingIndetermineFlow(a: Any) {
var x: Int
if (a is String) {
repeat(a.length) {
myRun { x = 42 }
}
}
else {
myRun { x = 43 }
}
x.inc()
}
fun funWithUnknownInvocations(block: () -> Unit) = block()
fun nestedIndefiniteAssignment() {
val x: Int
funWithUnknownInvocations { myRun { x = 42 } }
x.inc()
}
@@ -0,0 +1,28 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
fun <T, R> T.myLet(block: (T) -> R): R {
contract {
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
}
return block(this)
}
fun initializationWithReceiver(y: String) {
val x: Int
y.myLet { x = 42 }
x.inc()
}
fun initializationWithSafeCall(y: String?) {
val x: Int
y?.myLet { x = 42 }
x.inc()
}
fun sanityCheck(x: Int, y: String): Int {
y.let { return x }
}