Use of uninitialized variables in lambdas / object literals / local functions is forbidden now #KT-4475 Fixed
Local declarations CFA: variable initialization information before them is now taken into account
This commit is contained in:
@@ -3,7 +3,7 @@ fun foo(<!UNRESOLVED_REFERENCE!>@varargs<!> <!UNUSED_PARAMETER!>f<!> : Int) {}
|
||||
var bar : Int = 1
|
||||
set(<!UNRESOLVED_REFERENCE!>@varargs<!> v) {}
|
||||
|
||||
val x : (Int) -> Int = {<!UNRESOLVED_REFERENCE!>@varargs<!> <!TYPE_MISMATCH!>x<!> <!SYNTAX!>: Int -> x<!>}
|
||||
val x : (Int) -> Int = {<!UNRESOLVED_REFERENCE!>@varargs<!> <!TYPE_MISMATCH, UNINITIALIZED_VARIABLE!>x<!> <!SYNTAX!>: Int -> x<!>}
|
||||
|
||||
class Hello(<!UNRESOLVED_REFERENCE!>@varargs<!> <!UNUSED_PARAMETER!>args<!>: Any) {
|
||||
}
|
||||
@@ -6,7 +6,7 @@ fun foo(@test <!UNUSED_PARAMETER!>f<!> : Int) {}
|
||||
var bar : Int = 1
|
||||
set(@test v) {}
|
||||
|
||||
val x : (Int) -> Int = {@test <!TYPE_MISMATCH!>x<!> <!SYNTAX!>: Int -> x<!>} // todo fix parser annotation on lambda parameter
|
||||
val x : (Int) -> Int = {@test <!TYPE_MISMATCH, UNINITIALIZED_VARIABLE!>x<!> <!SYNTAX!>: Int -> x<!>} // todo fix parser annotation on lambda parameter
|
||||
|
||||
class Hello(@test <!UNUSED_PARAMETER!>args<!>: Any) {
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -271,7 +271,7 @@ fun foo() {
|
||||
z = 3
|
||||
}
|
||||
fun foo() {
|
||||
<!VAL_REASSIGNMENT!>y<!> = 10
|
||||
y = 10
|
||||
<!VAL_REASSIGNMENT!>z<!> = 13
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ class TestObjectExpression() {
|
||||
x = 1
|
||||
}
|
||||
fun inner1() {
|
||||
<!VAL_REASSIGNMENT!>y<!> = 101
|
||||
y = 101
|
||||
<!VAL_REASSIGNMENT!>a<!> = 231
|
||||
}
|
||||
fun inner2() {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
var x: Int
|
||||
fun bar() {
|
||||
x = 42
|
||||
}
|
||||
<!UNINITIALIZED_VARIABLE!>x<!>.hashCode()
|
||||
bar()
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
+4
-4
@@ -3,9 +3,9 @@ package o
|
||||
|
||||
class TestFunctionLiteral {
|
||||
val sum: (Int) -> Int = { x: Int ->
|
||||
sum(x - 1) + x
|
||||
<!UNINITIALIZED_VARIABLE!>sum<!>(x - 1) + x
|
||||
}
|
||||
val foo: () -> Unit = l@ ({ foo() })
|
||||
val foo: () -> Unit = l@ ({ <!UNINITIALIZED_VARIABLE!>foo<!>() })
|
||||
}
|
||||
|
||||
open class A(val a: A)
|
||||
@@ -16,14 +16,14 @@ class TestObjectLiteral {
|
||||
val x = <!UNINITIALIZED_VARIABLE!>obj<!>
|
||||
}
|
||||
fun foo() {
|
||||
val y = obj
|
||||
val y = <!UNINITIALIZED_VARIABLE!>obj<!>
|
||||
}
|
||||
}
|
||||
val obj1: A = l@ ( object: A(<!UNINITIALIZED_VARIABLE!>obj1<!>) {
|
||||
init {
|
||||
val x = <!UNINITIALIZED_VARIABLE!>obj1<!>
|
||||
}
|
||||
fun foo() = obj1
|
||||
fun foo() = <!UNINITIALIZED_VARIABLE!>obj1<!>
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun bar(f: () -> Unit) = f()
|
||||
|
||||
fun foo() {
|
||||
var v: Any
|
||||
bar { <!UNINITIALIZED_VARIABLE!>v<!>.hashCode() }
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun foo(): kotlin.Unit
|
||||
@@ -11,11 +11,11 @@ fun bar2() = {
|
||||
//properties
|
||||
//in a class
|
||||
class A() {
|
||||
val x = { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>x<!> }
|
||||
val x = { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>x<!> }
|
||||
}
|
||||
|
||||
//in a package
|
||||
val x = { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>x<!> }
|
||||
val x = { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>x<!> }
|
||||
|
||||
//KT-787 AssertionError on code 'val x = x'
|
||||
val z = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, UNINITIALIZED_VARIABLE!>z<!>
|
||||
|
||||
Reference in New Issue
Block a user