[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,37 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun getBoolean() = true
fun testSafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
x.inc()
val s = when (val y = run { x = 42; 32 }) {
0 -> {
x.inc() // TODO fix smart casts for captured variables
"0"
}
else -> "!= 0"
}
x.inc() // TODO fix smart casts for captured variables
}
fun testUnsafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
x.inc()
val s = when (val y = run { x = null; 32 }) {
0 -> {
x.<!UNRESOLVED_REFERENCE!>inc<!>() // NB smart cast should be impossible
"0"
}
else -> "!= 0"
}
x.<!UNRESOLVED_REFERENCE!>inc<!>() // NB smart cast should be impossible
}
@@ -0,0 +1,14 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun foo(): Any = 42
fun test(x: Any) {
val z1 = when (val y = foo()) {
42 -> "Magic: $y, $x"
else -> {
"Not magic: $y, $x"
}
}
val z2 = "Anyway, it was $<!UNRESOLVED_REFERENCE!>y<!>"
}
@@ -0,0 +1,43 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun testJumpOutInElvis(x: Int?) {
loop@ while (true) {
val y = when (val z = x ?: break@loop) {
0 -> "0"
else -> "not 0"
}
x.inc()
}
x.<!INAPPLICABLE_CANDIDATE!>inc<!>()
}
fun testJumpOutInElvisLikeIf(x: Int?) {
loop@ while (true) {
val y = when (val z = if (x == null) break@loop else x) {
0 -> "0"
else -> "not 0"
}
x.inc()
}
x.<!INAPPLICABLE_CANDIDATE!>inc<!>()
}
fun getBoolean() = true
fun testJumpOutInIf(x: Int?) {
loop@ while (true) {
val y = when (val z = if (getBoolean()) { x!!; break@loop } else x) {
0 -> "0"
else -> "not 0"
}
x.<!INAPPLICABLE_CANDIDATE!>inc<!>()
}
x.inc() // Actually, safe, but it's OK if it's error
}
@@ -0,0 +1,41 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VALUE
fun foo() {}
fun <T> bar(x: T, y: T) {}
fun test1() {
when (1) {
1 ->
when (val y = 2) {
2 -> foo()
}
}
}
fun test2() {
when (val x = 1) {
1 ->
when (val y = 2) {
2 -> foo()
}
}
}
fun test3() {
when (val x = 1) {
1 ->
when (val x = 2) {
2 -> foo()
}
}
}
fun test4() {
when (val x = 1) {
1 ->
when (val y = 2) {
2 -> bar(x, y)
}
}
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun testNoSubjectVariableName(x: Int?) {
val y = when (val<!SYNTAX!><!> = 42) {
0 -> "0"
else -> "not 0"
}
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VALUE
fun foo(): Any = 42
fun test1(x: Any) {
when (val y = foo()) {
is String -> y = ""
}
}
@@ -0,0 +1,27 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun foo(): Any = 42
fun useInt(i: Int) {}
fun testShadowingParameter(y: Any) {
when (val y = foo()) {
else -> {}
}
}
fun testShadowedInWhenBody(x: Any) {
when (val y = x) {
is String -> {
val y = y.length
useInt(y)
}
}
}
fun testShadowinLocalVariable() {
val y = foo()
when (val y = foo()) {
else -> {}
}
}
@@ -0,0 +1,49 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !WITH_NEW_INFERENCE
fun foo(s1: Int, s2: Int) = s1 + s2
fun test1(x: String?) =
when (val y = x?.length) {
null -> 0
else -> foo(x.length, y)
}
fun test2(x: String?) {
when (val y = run { x!! }) {
"foo" -> x.length
"bar" -> y.length
}
}
fun test3(x: String?, y: String?) {
when (val z = x ?: y!!) {
"foo" -> x.<!INAPPLICABLE_CANDIDATE!>length<!>
"bar" -> y.<!INAPPLICABLE_CANDIDATE!>length<!>
"baz" -> z.length
}
}
fun <T> id(x: T): T = x
fun test4(x: String?) {
when (val y = id(x!!)) {
"foo" -> x.length
"bar" -> y.length
}
}
class Inv<T>(val data: T)
fun test5(x: Inv<out Any?>) {
when (val y = x.data) {
is String -> y.length // should be ok
null -> x.data.<!UNRESOLVED_REFERENCE!>length<!> // should be error
}
}
fun test6(x: Inv<out String?>) {
when (val y = x.data) {
is String -> x.data.length // should be ok
}
}
@@ -0,0 +1,8 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
fun test(x: Any?) =
when (val y = x) {
is String -> "String, length = ${y.length}"
null -> "Null"
else -> "Any, hashCode = ${y.hashCode()}"
}
@@ -0,0 +1,18 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
enum class E { FIRST, SECOND }
fun testSmartcastToEnumInSubjectInitializer1(e: E?) {
val x1 = when (val ne = e!!) {
E.FIRST -> "f"
E.SECOND -> "s"
}
}
fun testSmartcastToEnumInSubjectInitializer2(e: E?) {
val x2 = when (val ne: Any = e!!) { // NB explicit type annotation
E.FIRST -> "f"
E.SECOND -> "s"
}
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
sealed class Either
class Left : Either()
class Right : Either()
fun testSmartcastToSealedInSubjectInitializer1(x: Any?) {
val y1 = when (val either = x as Either) {
is Left -> "L"
is Right -> "R"
}
}
fun testSmartcastToSealedInSubjectInitializer2(x: Any?) {
val y2 = when (val either: Any = x as Either) { // NB explicit type annotation
is Left -> "L"
is Right -> "R"
}
}
@@ -0,0 +1,7 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
fun test(data: String) =
when (data.length) {
0 -> -1
else -> 42
}
@@ -0,0 +1,8 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
fun test(x: Any) {
when (val y = x) {
is String -> {}
}
}
@@ -0,0 +1,16 @@
// !LANGUAGE: -VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun foo(): Any = 42
fun test(x: Any) {
// NB check that we still resolve 'y', even though current language version doesn' support variable declaration in when subject
val z1 = when (val y = foo()) {
42 -> "Magic: $y, $x"
else -> {
"Not magic: $y, $x"
}
}
val z2 = "Anyway, it was $<!UNRESOLVED_REFERENCE!>y<!>"
}
@@ -0,0 +1,29 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// WITH_RUNTIME
fun foo(): Any = 42
fun String.bar(): Any = 42
fun testSimpleValInWhenSubject() {
when (val y = foo()) {
}
}
fun testValWithoutInitializerWhenSubject() {
when (val y: Any) {
is String -> y.<!UNRESOLVED_REFERENCE!>length<!>
}
}
fun testVarInWhenSubject() {
when (var y = foo()) {
is String -> y.length
}
}
fun testDelegatedValInWhenSubject() {
when (val y by lazy { 42 }) {
}
}
@@ -0,0 +1,8 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
fun foo(): Any = 42
fun test() {
when (val x = foo()) {
}
}