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:
Mikhail Glukhikh
2015-11-11 13:05:40 +03:00
parent 89791dc85c
commit fe13f39de9
26 changed files with 245 additions and 105 deletions
@@ -126,7 +126,7 @@ public class PseudocodeVariablesData {
final LexicalScopeVariableInfo lexicalScopeVariableInfo = pseudocodeVariableDataCollector.getLexicalScopeVariableInfo();
return pseudocodeVariableDataCollector.collectData(
FORWARD, /*mergeDataWithLocalDeclarations=*/ false,
FORWARD, /*mergeDataWithLocalDeclarations=*/ true,
new InstructionDataMergeStrategy<VariableControlFlowState>() {
@NotNull
@Override
@@ -34,27 +34,27 @@ sink:
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
v(x: Int) INIT: in: {} out: {x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {x=D} out: {x=D}
w(x|<v0>) INIT: in: {x=D} out: {x=ID}
4 mark(val y = x + a use(a)) INIT: in: {x=ID} out: {x=ID}
v(val y = x + a) INIT: in: {x=ID} out: {x=ID, y=D} USE: in: {a=READ, x=READ} out: {a=READ, x=READ}
r(x) -> <v1> INIT: in: {x=ID, y=D} out: {x=ID, y=D} USE: in: {a=READ} out: {a=READ, x=READ}
3 <START> INIT: in: {a=ID, f=D} out: {a=ID, f=D}
v(x: Int) INIT: in: {a=ID, f=D} out: {a=ID, f=D, x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {a=ID, f=D, x=D} out: {a=ID, f=D, x=D}
w(x|<v0>) INIT: in: {a=ID, f=D, x=D} out: {a=ID, f=D, x=ID}
4 mark(val y = x + a use(a)) INIT: in: {a=ID, f=D, x=ID} out: {a=ID, f=D, x=ID}
v(val y = x + a) INIT: in: {a=ID, f=D, x=ID} out: {a=ID, f=D, x=ID, y=D} USE: in: {a=READ, x=READ} out: {a=READ, x=READ}
r(x) -> <v1> INIT: in: {a=ID, f=D, x=ID, y=D} out: {a=ID, f=D, x=ID, y=D} USE: in: {a=READ} out: {a=READ, x=READ}
r(a) -> <v2>
mark(x + a)
call(x + a, plus|<v1>, <v2>) -> <v3>
w(y|<v3>) INIT: in: {x=ID, y=D} out: {x=ID, y=ID} USE: in: {a=READ} out: {a=READ}
r(a) -> <v4> INIT: in: {x=ID, y=ID} out: {x=ID, y=ID} USE: in: {} out: {a=READ}
w(y|<v3>) INIT: in: {a=ID, f=D, x=ID, y=D} out: {a=ID, f=D, x=ID, y=ID} USE: in: {a=READ} out: {a=READ}
r(a) -> <v4> INIT: in: {a=ID, f=D, x=ID, y=ID} out: {a=ID, f=D, x=ID, y=ID} USE: in: {} out: {a=READ}
mark(use(a))
call(use(a), use|<v4>) -> <v5>
3 ret(*|<v5>) L4 INIT: in: {x=ID} out: {x=ID}
3 ret(*|<v5>) L4 INIT: in: {a=ID, f=D, x=ID} out: {a=ID, f=D, x=ID}
L4:
<END>
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
<SINK> INIT: in: {a=ID, f=D, x=ID} out: {a=ID, f=D, x=ID} USE: in: {} out: {}
=====================
== use ==
fun use(vararg a: Any?) = a
@@ -0,0 +1,60 @@
== bar ==
fun bar(f: () -> Unit) = f()
---------------------
L0:
1 <START> INIT: in: {} out: {}
v(f: () -> Unit) INIT: in: {} out: {f=D}
magic[FAKE_INITIALIZER](f: () -> Unit) -> <v0> INIT: in: {f=D} out: {f=D}
w(f|<v0>) INIT: in: {f=D} out: {f=ID} USE: in: {f=READ} out: {f=READ}
r(f) -> <v1> INIT: in: {f=ID} out: {f=ID} USE: in: {} out: {f=READ}
mark(f())
call(f(), invoke|<v1>) -> <v2>
ret(*|<v2>) L1
L1:
<END>
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {f=ID} out: {f=ID} USE: in: {} out: {}
=====================
== foo ==
fun foo() {
var v: Any
bar { v.hashCode() }
}
---------------------
L0:
1 <START> INIT: in: {} out: {} USE: in: {} out: {}
2 mark({ var v: Any bar { v.hashCode() } })
v(var v: Any) INIT: in: {} out: {v=D}
mark({ v.hashCode() }) INIT: in: {v=D} out: {v=D}
jmp?(L2)
d({ v.hashCode() }) USE: in: {v=READ} out: {v=READ}
L2 [after local declaration]:
r({ v.hashCode() }) -> <v0>
mark(bar { v.hashCode() })
call(bar { v.hashCode() }, bar|<v0>) -> <v1>
L1:
1 <END> INIT: in: {} out: {}
error:
<ERROR>
sink:
<SINK> USE: in: {} out: {}
=====================
== anonymous_0 ==
{ v.hashCode() }
---------------------
L3:
3 <START> INIT: in: {v=D} out: {v=D}
4 mark(v.hashCode())
mark(v.hashCode()) USE: in: {v=READ} out: {v=READ}
r(v) -> <v0> USE: in: {} out: {v=READ}
mark(hashCode())
call(hashCode(), hashCode|<v0>) -> <v1>
L4:
3 <END>
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {v=D} out: {v=D} USE: in: {} out: {}
=====================
@@ -0,0 +1,6 @@
fun bar(f: () -> Unit) = f()
fun foo() {
var v: Any
bar { v.hashCode() }
}
@@ -0,0 +1,25 @@
== bar ==
fun bar(f: () -> Unit) = f()
---------------------
<v0>: {<: () -> Unit} NEW: magic[FAKE_INITIALIZER](f: () -> Unit) -> <v0>
f <v1>: {<: () -> Unit} NEW: r(f) -> <v1>
f() <v2>: Unit NEW: call(f(), invoke|<v1>) -> <v2>
=====================
== foo ==
fun foo() {
var v: Any
bar { v.hashCode() }
}
---------------------
{ v.hashCode() } <v0>: {<: () -> Unit} NEW: r({ v.hashCode() }) -> <v0>
bar { v.hashCode() } <v1>: * NEW: call(bar { v.hashCode() }, bar|<v0>) -> <v1>
{ var v: Any bar { v.hashCode() } } <v1>: * COPY
=====================
== anonymous_0 ==
{ v.hashCode() }
---------------------
v <v0>: {<: Any} NEW: r(v) -> <v0>
hashCode() <v1>: * NEW: call(hashCode(), hashCode|<v0>) -> <v1>
v.hashCode() <v1>: * COPY
v.hashCode() <v1>: * COPY
=====================
@@ -27,20 +27,20 @@ sink:
}
---------------------
L3:
2 <START> INIT: in: {} out: {}
v(x: Int) INIT: in: {} out: {x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {x=D} out: {x=D}
w(x|<v0>) INIT: in: {x=D} out: {x=ID}
3 mark(sum(x - 1) + x) INIT: in: {x=ID} out: {x=ID}
magic[IMPLICIT_RECEIVER](sum) -> <v1> USE: in: {sum=READ, x=READ} out: {sum=READ, x=READ}
r(sum|<v1>) -> <v2> USE: in: {x=READ} out: {sum=READ, x=READ}
2 <START> INIT: in: {sum=D} out: {sum=D}
v(x: Int) INIT: in: {sum=D} out: {sum=D, x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {sum=D, x=D} out: {sum=D, x=D}
w(x|<v0>) INIT: in: {sum=D, x=D} out: {sum=D, x=ID}
3 mark(sum(x - 1) + x) INIT: in: {sum=D, x=ID} out: {sum=D, x=ID}
magic[IMPLICIT_RECEIVER](sum) -> <v1> USE: in: {sum=READ, x=READ} out: {sum=READ, x=READ}
r(sum|<v1>) -> <v2> USE: in: {x=READ} out: {sum=READ, x=READ}
r(x) -> <v3>
r(1) -> <v4>
mark(x - 1)
call(x - 1, minus|<v3>, <v4>) -> <v5>
mark(sum(x - 1))
call(sum(x - 1), invoke|<v2>, <v5>) -> <v6> USE: in: {x=READ} out: {x=READ}
r(x) -> <v7> USE: in: {} out: {x=READ}
call(sum(x - 1), invoke|<v2>, <v5>) -> <v6> USE: in: {x=READ} out: {x=READ}
r(x) -> <v7> USE: in: {} out: {x=READ}
mark(sum(x - 1) + x)
call(sum(x - 1) + x, plus|<v6>, <v7>) -> <v8>
2 ret(*|<v8>) L4
@@ -49,7 +49,7 @@ L4:
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
<SINK> INIT: in: {sum=D, x=ID} out: {sum=D, x=ID} USE: in: {} out: {}
=====================
== A ==
open class A(val a: A)
@@ -109,18 +109,18 @@ fun foo() {
}
---------------------
L3:
2 <START> INIT: in: {} out: {}
2 <START> INIT: in: {obj=D} out: {obj=D}
3 mark({ val y = obj })
v(val y = obj) INIT: in: {} out: {y=D}
magic[IMPLICIT_RECEIVER](obj) -> <v0> INIT: in: {y=D} out: {y=D} USE: in: {obj=READ} out: {obj=READ}
r(obj|<v0>) -> <v1> USE: in: {} out: {obj=READ}
w(y|<v1>) INIT: in: {y=D} out: {y=ID}
v(val y = obj) INIT: in: {obj=D} out: {obj=D, y=D}
magic[IMPLICIT_RECEIVER](obj) -> <v0> INIT: in: {obj=D, y=D} out: {obj=D, y=D} USE: in: {obj=READ} out: {obj=READ}
r(obj|<v0>) -> <v1> USE: in: {} out: {obj=READ}
w(y|<v1>) INIT: in: {obj=D, y=D} out: {obj=D, y=ID}
L4:
2 <END> INIT: in: {} out: {}
2 <END> INIT: in: {obj=D} out: {obj=D}
error:
<ERROR>
<ERROR> INIT: in: {} out: {}
sink:
<SINK> USE: in: {} out: {}
<SINK> INIT: in: {obj=D} out: {obj=D} USE: in: {} out: {}
=====================
== TestOther ==
class TestOther {
@@ -38,21 +38,21 @@ sink:
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
v(x: Int) INIT: in: {} out: {x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {x=D} out: {x=D}
w(x|<v0>) INIT: in: {x=D} out: {x=ID}
4 mark(val a = x + b) INIT: in: {x=ID} out: {x=ID}
v(val a = x + b) INIT: in: {x=ID} out: {a=D, x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {a=D, x=ID} out: {a=D, x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
3 <START> INIT: in: {b=ID, f=D} out: {b=ID, f=D}
v(x: Int) INIT: in: {b=ID, f=D} out: {b=ID, f=D, x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {b=ID, f=D, x=D} out: {b=ID, f=D, x=D}
w(x|<v0>) INIT: in: {b=ID, f=D, x=D} out: {b=ID, f=D, x=ID}
4 mark(val a = x + b) INIT: in: {b=ID, f=D, x=ID} out: {b=ID, f=D, x=ID}
v(val a = x + b) INIT: in: {b=ID, f=D, x=ID} out: {a=D, b=ID, f=D, x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {a=D, b=ID, f=D, x=ID} out: {a=D, b=ID, f=D, x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
mark(x + b)
call(x + b, plus|<v1>, <v2>) -> <v3>
w(a|<v3>) INIT: in: {a=D, x=ID} out: {a=ID, x=ID}
w(a|<v3>) INIT: in: {a=D, b=ID, f=D, x=ID} out: {a=ID, b=ID, f=D, x=ID}
L4:
3 <END> INIT: in: {x=ID} out: {x=ID}
3 <END> INIT: in: {b=ID, f=D, x=ID} out: {b=ID, f=D, x=ID}
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
<SINK> INIT: in: {b=ID, f=D, x=ID} out: {b=ID, f=D, x=ID} USE: in: {} out: {}
=====================
@@ -43,16 +43,16 @@ fun foo() {
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
3 <START> INIT: in: {x=ID} out: {x=ID}
4 mark({ val b = x })
v(val b = x) INIT: in: {} out: {b=D}
magic[IMPLICIT_RECEIVER](x) -> <v0> INIT: in: {b=D} out: {b=D} USE: in: {x=READ} out: {x=READ}
r(x|<v0>) -> <v1> USE: in: {} out: {x=READ}
w(b|<v1>) INIT: in: {b=D} out: {b=ID}
v(val b = x) INIT: in: {x=ID} out: {b=D, x=ID}
magic[IMPLICIT_RECEIVER](x) -> <v0> INIT: in: {b=D, x=ID} out: {b=D, x=ID} USE: in: {x=READ} out: {x=READ}
r(x|<v0>) -> <v1> USE: in: {} out: {x=READ}
w(b|<v1>) INIT: in: {b=D, x=ID} out: {b=ID, x=ID}
L4:
3 <END> INIT: in: {} out: {}
3 <END> INIT: in: {x=ID} out: {x=ID}
error:
<ERROR>
<ERROR> INIT: in: {} out: {}
sink:
<SINK> USE: in: {} out: {}
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
=====================
@@ -34,21 +34,21 @@ fun local(x: Int) {
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
v(x: Int) INIT: in: {} out: {x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {x=D} out: {x=D}
w(x|<v0>) INIT: in: {x=D} out: {x=ID}
4 mark({ val a = x + b }) INIT: in: {x=ID} out: {x=ID}
v(val a = x + b) INIT: in: {x=ID} out: {a=D, x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {a=D, x=ID} out: {a=D, x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
3 <START> INIT: in: {b=ID} out: {b=ID}
v(x: Int) INIT: in: {b=ID} out: {b=ID, x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {b=ID, x=D} out: {b=ID, x=D}
w(x|<v0>) INIT: in: {b=ID, x=D} out: {b=ID, x=ID}
4 mark({ val a = x + b }) INIT: in: {b=ID, x=ID} out: {b=ID, x=ID}
v(val a = x + b) INIT: in: {b=ID, x=ID} out: {a=D, b=ID, x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {a=D, b=ID, x=ID} out: {a=D, b=ID, x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
mark(x + b)
call(x + b, plus|<v1>, <v2>) -> <v3>
w(a|<v3>) INIT: in: {a=D, x=ID} out: {a=ID, x=ID}
w(a|<v3>) INIT: in: {a=D, b=ID, x=ID} out: {a=ID, b=ID, x=ID}
L4:
3 <END> INIT: in: {x=ID} out: {x=ID}
3 <END> INIT: in: {b=ID, x=ID} out: {b=ID, x=ID}
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
<SINK> INIT: in: {b=ID, x=ID} out: {b=ID, x=ID} USE: in: {} out: {}
=====================
@@ -30,12 +30,12 @@ sink:
fun local(x: Int) = x + b
---------------------
L3:
3 <START> INIT: in: {} out: {}
v(x: Int) INIT: in: {} out: {x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {x=D} out: {x=D}
w(x|<v0>) INIT: in: {x=D} out: {x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {x=ID} out: {x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
3 <START> INIT: in: {b=ID} out: {b=ID}
v(x: Int) INIT: in: {b=ID} out: {b=ID, x=D}
magic[FAKE_INITIALIZER](x: Int) -> <v0> INIT: in: {b=ID, x=D} out: {b=ID, x=D}
w(x|<v0>) INIT: in: {b=ID, x=D} out: {b=ID, x=ID} USE: in: {b=READ, x=READ} out: {b=READ, x=READ}
r(x) -> <v1> INIT: in: {b=ID, x=ID} out: {b=ID, x=ID} USE: in: {b=READ} out: {b=READ, x=READ}
r(b) -> <v2> USE: in: {} out: {b=READ}
mark(x + b)
call(x + b, plus|<v1>, <v2>) -> <v3>
ret(*|<v3>) L4
@@ -44,5 +44,5 @@ L4:
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=ID} out: {x=ID} USE: in: {} out: {}
<SINK> INIT: in: {b=ID, x=ID} out: {b=ID, x=ID} USE: in: {} out: {}
=====================
@@ -43,15 +43,15 @@ fun foo() {
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
3 <START> INIT: in: {bar=D} out: {bar=D}
4 mark({ val a = 2 })
v(val a = 2) INIT: in: {} out: {a=D}
r(2) -> <v0> INIT: in: {a=D} out: {a=D}
w(a|<v0>) INIT: in: {a=D} out: {a=ID}
v(val a = 2) INIT: in: {bar=D} out: {a=D, bar=D}
r(2) -> <v0> INIT: in: {a=D, bar=D} out: {a=D, bar=D}
w(a|<v0>) INIT: in: {a=D, bar=D} out: {a=ID, bar=D}
L4:
3 <END> INIT: in: {} out: {}
3 <END> INIT: in: {bar=D} out: {bar=D}
error:
<ERROR>
<ERROR> INIT: in: {} out: {}
sink:
<SINK> USE: in: {} out: {}
<SINK> INIT: in: {bar=D} out: {bar=D} USE: in: {} out: {}
=====================
@@ -15,18 +15,18 @@ L0:
1 <START> INIT: in: {} out: {}
2 mark({ class A { var a : Int get() { return field } set(v: Int) { field = v } } })
v(var a : Int get() { return field } set(v: Int) { field = v }) INIT: in: {} out: {a=D}
jmp?(L2) INIT: in: {a=D} out: {a=D} USE: in: {field=ONLY_WRITTEN_NEVER_READ, field=READ} out: {field=ONLY_WRITTEN_NEVER_READ, field=READ}
d(get() { return field }) USE: in: {field=READ} out: {field=READ}
jmp?(L2) INIT: in: {a=D} out: {a=D} USE: in: {field=ONLY_WRITTEN_NEVER_READ, field=READ} out: {field=ONLY_WRITTEN_NEVER_READ, field=READ}
d(get() { return field }) USE: in: {field=READ} out: {field=READ}
L2 [after local declaration]:
jmp?(L5)
d(set(v: Int) { field = v }) USE: in: {field=ONLY_WRITTEN_NEVER_READ} out: {field=ONLY_WRITTEN_NEVER_READ}
d(set(v: Int) { field = v }) INIT: in: {a=D, field=I} out: {a=D, field=I} USE: in: {field=ONLY_WRITTEN_NEVER_READ} out: {field=ONLY_WRITTEN_NEVER_READ}
L1:
L5 [after local declaration]:
1 <END> INIT: in: {} out: {}
error:
<ERROR>
sink:
<SINK> USE: in: {} out: {}
<SINK> INIT: in: {field=I} out: {field=I} USE: in: {} out: {}
=====================
== get_a ==
get() {
@@ -34,16 +34,16 @@ get() {
}
---------------------
L3:
3 <START> INIT: in: {} out: {}
4 mark({ return field }) USE: in: {field=READ} out: {field=READ}
r(field) -> <v0> USE: in: {} out: {field=READ}
3 <START> INIT: in: {a=D} out: {a=D}
4 mark({ return field }) USE: in: {field=READ} out: {field=READ}
r(field) -> <v0> USE: in: {} out: {field=READ}
ret(*|<v0>) L4
L4:
3 <END>
error:
<ERROR>
<ERROR> INIT: in: {} out: {}
sink:
<SINK> USE: in: {} out: {}
<SINK> INIT: in: {a=D} out: {a=D} USE: in: {} out: {}
=====================
== set_a ==
set(v: Int) {
@@ -51,17 +51,17 @@ set(v: Int) {
}
---------------------
L6:
3 <START> INIT: in: {} out: {}
v(v: Int) INIT: in: {} out: {v=D}
magic[FAKE_INITIALIZER](v: Int) -> <v0> INIT: in: {v=D} out: {v=D}
w(v|<v0>) INIT: in: {v=D} out: {v=ID}
4 mark({ field = v }) INIT: in: {v=ID} out: {v=ID} USE: in: {field=ONLY_WRITTEN_NEVER_READ, v=READ} out: {field=ONLY_WRITTEN_NEVER_READ, v=READ}
r(v) -> <v1> USE: in: {field=ONLY_WRITTEN_NEVER_READ} out: {field=ONLY_WRITTEN_NEVER_READ, v=READ}
w(field|<v1>) INIT: in: {v=ID} out: {field=I, v=ID} USE: in: {} out: {field=ONLY_WRITTEN_NEVER_READ}
3 <START> INIT: in: {a=D} out: {a=D}
v(v: Int) INIT: in: {a=D} out: {a=D, v=D}
magic[FAKE_INITIALIZER](v: Int) -> <v0> INIT: in: {a=D, v=D} out: {a=D, v=D}
w(v|<v0>) INIT: in: {a=D, v=D} out: {a=D, v=ID}
4 mark({ field = v }) INIT: in: {a=D, v=ID} out: {a=D, v=ID} USE: in: {field=ONLY_WRITTEN_NEVER_READ, v=READ} out: {field=ONLY_WRITTEN_NEVER_READ, v=READ}
r(v) -> <v1> USE: in: {field=ONLY_WRITTEN_NEVER_READ} out: {field=ONLY_WRITTEN_NEVER_READ, v=READ}
w(field|<v1>) INIT: in: {a=D, v=ID} out: {a=D, field=I, v=ID} USE: in: {} out: {field=ONLY_WRITTEN_NEVER_READ}
L7:
3 <END> INIT: in: {field=I, v=ID} out: {field=I, v=ID}
3 <END> INIT: in: {a=D, field=I, v=ID} out: {a=D, field=I, v=ID}
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {field=I, v=ID} out: {field=I, v=ID} USE: in: {} out: {}
<SINK> INIT: in: {a=D, field=I, v=ID} out: {a=D, field=I, v=ID} USE: in: {} out: {}
=====================
+3 -2
View File
@@ -1,8 +1,9 @@
object RefreshQueue {
val any = Any()
val workerThread: Thread = Thread(object : Runnable {
override fun run() {
val a = workerThread
val b = RefreshQueue.workerThread
val a = any
val b = RefreshQueue.any
if (a != b) throw AssertionError()
}
})
+4 -1
View File
@@ -1,7 +1,10 @@
public object RefreshQueue {
private val any = Any()
private val workerThread: Thread = Thread(object : Runnable {
override fun run() {
workerThread.isInterrupted()
any.hashCode()
}
});
@@ -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) {
}
@@ -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() {
@@ -0,0 +1,8 @@
fun foo() {
var x: Int
fun bar() {
x = 42
}
<!UNINITIALIZED_VARIABLE!>x<!>.hashCode()
bar()
}
@@ -0,0 +1,3 @@
package
public fun foo(): kotlin.Unit
@@ -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<!>
})
}
@@ -0,0 +1,6 @@
fun bar(f: () -> Unit) = f()
fun foo() {
var v: Any
bar { <!UNINITIALIZED_VARIABLE!>v<!>.hashCode() }
}
@@ -0,0 +1,4 @@
package
public fun bar(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public fun foo(): kotlin.Unit
+2 -2
View File
@@ -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<!>
@@ -61,6 +61,12 @@ public class DataFlowTestGenerated extends AbstractDataFlowTest {
doTest(fileName);
}
@TestMetadata("UseUninitializedInLambda.kt")
public void testUseUninitializedInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/basic/UseUninitializedInLambda.kt");
doTest(fileName);
}
@TestMetadata("VariablesInitialization.kt")
public void testVariablesInitialization() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/basic/VariablesInitialization.kt");
@@ -777,6 +777,12 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
doTest(fileName);
}
@TestMetadata("UseUninitializedInLambda.kt")
public void testUseUninitializedInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/basic/UseUninitializedInLambda.kt");
doTest(fileName);
}
@TestMetadata("VariablesInitialization.kt")
public void testVariablesInitialization() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/basic/VariablesInitialization.kt");
@@ -2745,6 +2745,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("initializationInLambda.kt")
public void testInitializationInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/initializationInLambda.kt");
doTest(fileName);
}
@TestMetadata("kt1001.kt")
public void testKt1001() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.kt");
@@ -2991,6 +2997,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("useUninitializedInLambda.kt")
public void testUseUninitializedInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.kt");
doTest(fileName);
}
@TestMetadata("varInitializationInIfInCycle.kt")
public void testVarInitializationInIfInCycle() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/varInitializationInIfInCycle.kt");