Analyze Data Flow: Initial implementation

#KT-11994 In Progress
This commit is contained in:
Alexey Sedunov
2017-05-18 18:27:21 +03:00
parent 3f104833ba
commit 858b454138
92 changed files with 1450 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
// FLOW: IN
fun test(o: Any) {
val <caret>x = o as String
}
+4
View File
@@ -0,0 +1,4 @@
4 val <bold>x = o as String</bold>
4 val x = <bold>o as String</bold>
4 val x = <bold>o</bold> as String
3 fun test(<bold>o: Any</bold>) {
+13
View File
@@ -0,0 +1,13 @@
// FLOW: IN
fun foo(<caret>n: Int, s: String = "???") {
}
fun test() {
foo(1)
foo(1, "2")
foo(1, s = "2")
foo(n = 1, s = "2")
foo(s = "2", n = 1)
}
+6
View File
@@ -0,0 +1,6 @@
3 fun foo(<bold>n: Int</bold>, s: String = "???") {
8 foo(<bold>1</bold>)
9 foo(<bold>1</bold>, "2")
10 foo(<bold>1</bold>, s = "2")
11 foo(n = <bold>1</bold>, s = "2")
12 foo(s = "2", n = <bold>1</bold>)
+13
View File
@@ -0,0 +1,13 @@
// FLOW: IN
fun foo(n: Int, <caret>s: String = "???") {
}
fun test() {
foo(1)
foo(1, "2")
foo(1, s = "2")
foo(n = 1, s = "2")
foo(s = "2", n = 1)
}
@@ -0,0 +1,6 @@
3 fun foo(n: Int, <bold>s: String = "???"</bold>) {
3 fun foo(n: Int, s: String = <bold>"???"</bold>) {
9 foo(1, <bold>"2"</bold>)
10 foo(1, s = <bold>"2"</bold>)
11 foo(n = 1, s = <bold>"2"</bold>)
12 foo(s = <bold>"2"</bold>, n = 1)
+3
View File
@@ -0,0 +1,3 @@
// FLOW: IN
fun <caret>foo(n: Int) = n + 1
@@ -0,0 +1,2 @@
3 fun <bold>foo(n: Int) = n + 1</bold>
3 fun foo(n: Int) = <bold>n + 1</bold>
@@ -0,0 +1,6 @@
// FLOW: IN
fun <caret>foo(n: Int): Int {
if (n > 0) return n
return -n
}
@@ -0,0 +1,4 @@
3 fun <bold>foo(n: Int): Int {</bold>
4 if (n > 0) return <bold>n</bold>
3 fun foo(<bold>n: Int</bold>): Int {
5 return <bold>-n</bold>
+5
View File
@@ -0,0 +1,5 @@
// FLOW: IN
fun test(m: Int, n: Int) {
val <caret>x = if (m > 1) n else 1
}
+5
View File
@@ -0,0 +1,5 @@
4 val <bold>x = if (m > 1) n else 1</bold>
4 val x = <bold>if (m > 1) n else 1</bold>
4 val x = if (m > 1) <bold>n</bold> else 1
3 fun test(m: Int, <bold>n: Int</bold>) {
4 val x = if (m > 1) n else <bold>1</bold>
+6
View File
@@ -0,0 +1,6 @@
// FLOW: IN
fun test(n: Int) {
val <caret>x = n
val y = x
}
+3
View File
@@ -0,0 +1,3 @@
4 val <bold>x = n</bold>
4 val x = <bold>n</bold>
3 fun test(<bold>n: Int</bold>) {
+7
View File
@@ -0,0 +1,7 @@
// FLOW: IN
fun test(n: Int) {
var <caret>x = n
val y = x
x = 0
}
+4
View File
@@ -0,0 +1,4 @@
4 var <bold>x = n</bold>
4 var x = <bold>n</bold>
3 fun test(<bold>n: Int</bold>) {
6 x = <bold>0</bold>
+10
View File
@@ -0,0 +1,10 @@
// FLOW: IN
class A {
val <caret>x: Int = 1
val y = x
fun test() {
val y = x
}
}
@@ -0,0 +1,2 @@
4 val <bold>x: Int = 1</bold>
4 val x: Int = <bold>1</bold>
@@ -0,0 +1,15 @@
// FLOW: IN
class A {
val <caret>x: Int
init {
x = 1
}
val y = x
fun test() {
val y = x
}
}
@@ -0,0 +1,2 @@
4 val <bold>x: Int</bold>
7 x = <bold>1</bold>
+11
View File
@@ -0,0 +1,11 @@
// FLOW: IN
class A {
var <caret>x: Int = 1
val y = x
fun test() {
val y = x
x = 2
}
}
@@ -0,0 +1,3 @@
4 var <bold>x: Int = 1</bold>
4 var x: Int = <bold>1</bold>
9 x = <bold>2</bold>
@@ -0,0 +1,16 @@
// FLOW: IN
class A {
var <caret>x: Int
init {
x = 1
}
val y = x
fun test() {
val y = x
x = 2
}
}
@@ -0,0 +1,3 @@
4 var <bold>x: Int</bold>
7 x = <bold>1</bold>
14 x = <bold>2</bold>
+5
View File
@@ -0,0 +1,5 @@
// FLOW: IN
fun test(s: String?) {
val <caret>x = s!!
}
@@ -0,0 +1,4 @@
4 val <bold>x = s!!</bold>
4 val x = <bold>s!!</bold>
4 val x = <bold>s</bold>!!
3 fun test(<bold>s: String?</bold>) {
@@ -0,0 +1,17 @@
// FLOW: IN
open class A(<caret>n: Int, s: String = "???")
class B1: A(1)
class B2: A(1, "2")
class B3: A(1, s = "2")
class B4: A(n = 1, s = "2")
class B5: A(s = "2", n = 1)
fun test() {
A(1)
A(1, "2")
A(1, s = "2")
A(n = 1, s = "2")
A(s = "2", n = 1)
}
@@ -0,0 +1,11 @@
3 open class A(<bold>n: Int</bold>, s: String = "???")
5 class B1: A(<bold>1</bold>)
6 class B2: A(<bold>1</bold>, "2")
7 class B3: A(<bold>1</bold>, s = "2")
8 class B4: A(n = <bold>1</bold>, s = "2")
9 class B5: A(s = "2", n = <bold>1</bold>)
12 A(<bold>1</bold>)
13 A(<bold>1</bold>, "2")
14 A(<bold>1</bold>, s = "2")
15 A(n = <bold>1</bold>, s = "2")
16 A(s = "2", n = <bold>1</bold>)
@@ -0,0 +1,17 @@
// FLOW: IN
open class A(n: Int, <caret>s: String = "???")
class B1: A(1)
class B2: A(1, "2")
class B3: A(1, s = "2")
class B4: A(n = 1, s = "2")
class B5: A(s = "2", n = 1)
fun test() {
A(1)
A(1, "2")
A(1, s = "2")
A(n = 1, s = "2")
A(s = "2", n = 1)
}
@@ -0,0 +1,10 @@
3 open class A(n: Int, <bold>s: String = "???"</bold>)
3 open class A(n: Int, s: String = <bold>"???"</bold>)
6 class B2: A(1, <bold>"2"</bold>)
7 class B3: A(1, s = <bold>"2"</bold>)
8 class B4: A(n = 1, s = <bold>"2"</bold>)
9 class B5: A(s = <bold>"2"</bold>, n = 1)
13 A(1, <bold>"2"</bold>)
14 A(1, s = <bold>"2"</bold>)
15 A(n = 1, s = <bold>"2"</bold>)
16 A(s = <bold>"2"</bold>, n = 1)
+5
View File
@@ -0,0 +1,5 @@
// FLOW: IN
fun test(o: Any) {
val <caret>x = o as? String
}
+4
View File
@@ -0,0 +1,4 @@
4 val <bold>x = o as? String</bold>
4 val x = <bold>o as? String</bold>
4 val x = <bold>o</bold> as? String
3 fun test(<bold>o: Any</bold>) {
@@ -0,0 +1,19 @@
// FLOW: IN
open class A {
constructor(<caret>n: Int, s: String = "???")
}
class B1: A(1)
class B2: A(1, "2")
class B3: A(1, s = "2")
class B4: A(n = 1, s = "2")
class B5: A(s = "2", n = 1)
fun test() {
A(1)
A(1, "2")
A(1, s = "2")
A(n = 1, s = "2")
A(s = "2", n = 1)
}
@@ -0,0 +1,11 @@
4 constructor(<bold>n: Int</bold>, s: String = "???")
7 class B1: A(<bold>1</bold>)
8 class B2: A(<bold>1</bold>, "2")
9 class B3: A(<bold>1</bold>, s = "2")
10 class B4: A(n = <bold>1</bold>, s = "2")
11 class B5: A(s = "2", n = <bold>1</bold>)
14 A(<bold>1</bold>)
15 A(<bold>1</bold>, "2")
16 A(<bold>1</bold>, s = "2")
17 A(n = <bold>1</bold>, s = "2")
18 A(s = "2", n = <bold>1</bold>)
@@ -0,0 +1,19 @@
// FLOW: IN
open class A {
constructor(n: Int, <caret>s: String = "???")
}
class B1: A(1)
class B2: A(1, "2")
class B3: A(1, s = "2")
class B4: A(n = 1, s = "2")
class B5: A(s = "2", n = 1)
fun test() {
A(1)
A(1, "2")
A(1, s = "2")
A(n = 1, s = "2")
A(s = "2", n = 1)
}
@@ -0,0 +1,10 @@
4 constructor(n: Int, <bold>s: String = "???"</bold>)
4 constructor(n: Int, s: String = <bold>"???"</bold>)
8 class B2: A(1, <bold>"2"</bold>)
9 class B3: A(1, s = <bold>"2"</bold>)
10 class B4: A(n = 1, s = <bold>"2"</bold>)
11 class B5: A(s = <bold>"2"</bold>, n = 1)
15 A(1, <bold>"2"</bold>)
16 A(1, s = <bold>"2"</bold>)
17 A(n = 1, s = <bold>"2"</bold>)
18 A(s = <bold>"2"</bold>, n = 1)
+7
View File
@@ -0,0 +1,7 @@
// FLOW: IN
val <caret>foo: Int = 1
fun test() {
val x = foo
}
+2
View File
@@ -0,0 +1,2 @@
3 val <bold>foo: Int = 1</bold>
3 val foo: Int = <bold>1</bold>
+8
View File
@@ -0,0 +1,8 @@
// FLOW: IN
var <caret>foo: Int = 1
fun test() {
val x = foo
foo = 2
}
+3
View File
@@ -0,0 +1,3 @@
3 var <bold>foo: Int = 1</bold>
3 var foo: Int = <bold>1</bold>
7 foo = <bold>2</bold>
+9
View File
@@ -0,0 +1,9 @@
// FLOW: IN
fun test(m: Int, n: Int) {
val <caret>x = when (m) {
1 -> 1
2 -> n
else -> 0
}
}
@@ -0,0 +1,6 @@
4 val <bold>x = when (m) {</bold>
4 val x = <bold>when (m) {</bold>
5 1 -> <bold>1</bold>
6 2 -> <bold>n</bold>
3 fun test(m: Int, <bold>n: Int</bold>) {
7 else -> <bold>0</bold>
+10
View File
@@ -0,0 +1,10 @@
// FLOW: OUT
fun foo(n: Int) {
val y = n
}
fun test() {
val x = <caret>1
foo(x)
}
+4
View File
@@ -0,0 +1,4 @@
7 val x = <bold>1</bold>
7 val <bold>x = 1</bold>
2 fun foo(<bold>n: Int</bold>) {
3 val <bold>y = n</bold>
+6
View File
@@ -0,0 +1,6 @@
// FLOW: OUT
fun test(<caret>o: Any) {
val x = o as String
val y = o as? String
}
+5
View File
@@ -0,0 +1,5 @@
3 fun test(<bold>o: Any</bold>) {
4 val x = <bold>o as String</bold>
4 val <bold>x = o as String</bold>
5 val y = <bold>o as? String</bold>
5 val <bold>y = o as? String</bold>
+7
View File
@@ -0,0 +1,7 @@
// FLOW: OUT
fun foo(n: Int): Int = <caret>n
fun test() {
val x = foo(1)
}
@@ -0,0 +1,4 @@
3 fun foo(n: Int): Int = <bold>n</bold>
3 fun <bold>foo(n: Int): Int = n</bold>
6 val x = <bold>foo(1)</bold>
6 val <bold>x = foo(1)</bold>
+14
View File
@@ -0,0 +1,14 @@
// FLOW: OUT
fun foo(<caret>n: Int) {
val x = n
val y: Int
y = n
bar(n)
}
fun bar(m: Int) {
}
@@ -0,0 +1,4 @@
3 fun foo(<bold>n: Int</bold>) {
4 val <bold>x = n</bold>
6 val <bold>y: Int</bold>
12 fun bar(<bold>m: Int</bold>) {
+9
View File
@@ -0,0 +1,9 @@
// FLOW: OUT
fun foo(n: Int): Int {
return <caret>n
}
fun test() {
val x = foo(1)
}
@@ -0,0 +1,4 @@
4 return <bold>n</bold>
3 fun <bold>foo(n: Int): Int {</bold>
8 val x = <bold>foo(1)</bold>
8 val <bold>x = foo(1)</bold>
+9
View File
@@ -0,0 +1,9 @@
// FLOW: OUT
fun <caret>foo(n: Int) {
}
fun test(m: Int) {
val x = foo(1)
}
@@ -0,0 +1,3 @@
3 fun <bold>foo(n: Int) {</bold>
8 val x = <bold>foo(1)</bold>
8 val <bold>x = foo(1)</bold>
+9
View File
@@ -0,0 +1,9 @@
// FLOW: OUT
class A {
operator fun <caret>get(n: Int) = this
}
fun test() {
val x = A()[2]
}
+3
View File
@@ -0,0 +1,3 @@
4 operator fun <bold>get(n: Int) = this</bold>
8 val x = <bold>A()[2]</bold>
8 val <bold>x = A()[2]</bold>
+5
View File
@@ -0,0 +1,5 @@
// FLOW: OUT
fun test(m: Int, <caret>n: Int) {
val x = if (m > 1) n else 1
}
+2
View File
@@ -0,0 +1,2 @@
3 fun test(m: Int, <bold>n: Int</bold>) {
4 val <bold>x = if (m > 1) n else 1</bold>
+14
View File
@@ -0,0 +1,14 @@
// FLOW: OUT
fun foo(n: Int) {
}
fun test() {
val <caret>x = 1
val y = x
val z: Int
z = x
foo(x)
}
@@ -0,0 +1,4 @@
6 val <bold>x = 1</bold>
8 val <bold>y = x</bold>
10 val <bold>z: Int</bold>
2 fun foo(<bold>n: Int</bold>) {
+19
View File
@@ -0,0 +1,19 @@
// FLOW: OUT
class A {
val <caret>x = 1
val y = x
val z: Int
init {
z = x
bar(x)
}
fun bar(m: Int) {
}
}
@@ -0,0 +1,4 @@
4 val <bold>x = 1</bold>
6 val <bold>y = x</bold>
8 val <bold>z: Int</bold>
16 fun bar(<bold>m: Int</bold>) {
+5
View File
@@ -0,0 +1,5 @@
// FLOW: OUT
fun test(<caret>s: String?) {
val x = s!!
}
@@ -0,0 +1,3 @@
3 fun test(<bold>s: String?</bold>) {
4 val x = <bold>s!!</bold>
4 val <bold>x = s!!</bold>
+9
View File
@@ -0,0 +1,9 @@
// FLOW: OUT
class A {
operator fun <caret>plus(n: Int) = this
}
fun test() {
val x = A() + 2
}
@@ -0,0 +1,3 @@
4 operator fun <bold>plus(n: Int) = this</bold>
8 val x = <bold>A() + 2</bold>
8 val <bold>x = A() + 2</bold>
+15
View File
@@ -0,0 +1,15 @@
// FLOW: OUT
open class A<caret>(n: Int) {
constructor() : this(1)
}
class B : A(1)
class C : A {
constructor() : super(1)
}
fun test() {
val x = A(1)
}
@@ -0,0 +1,6 @@
3 open class A<bold>(n: Int)</bold> {
7 class B : <bold>A(1)</bold>
14 val x = <bold>A(1)</bold>
14 val <bold>x = A(1)</bold>
4 constructor() : <bold>this(1)</bold>
10 constructor() : <bold>super(1)</bold>
@@ -0,0 +1,17 @@
// FLOW: OUT
class A(<caret>n: Int) {
val x = n
val y: Int
init {
y = n
bar(n)
}
fun bar(m: Int) {
}
}
@@ -0,0 +1,4 @@
3 class A(<bold>n: Int</bold>) {
4 val <bold>x = n</bold>
6 val <bold>y: Int</bold>
14 fun bar(<bold>m: Int</bold>) {
@@ -0,0 +1,17 @@
// FLOW: OUT
open class A {
<caret>constructor(n: Int)
constructor() : this(1)
}
class B : A(1)
class C : A {
constructor() : super(1)
}
fun test() {
val x = A(1)
}
@@ -0,0 +1,6 @@
4 <bold>constructor(n: Int)</bold>
9 class B : <bold>A(1)</bold>
16 val x = <bold>A(1)</bold>
16 val <bold>x = A(1)</bold>
6 constructor() : <bold>this(1)</bold>
12 constructor() : <bold>super(1)</bold>
+21
View File
@@ -0,0 +1,21 @@
// FLOW: OUT
val <caret>x = 1
val y = x
fun test() {
val y = x
val z: Int
init {
z = x
bar(x)
}
}
fun bar(m: Int) {
}
@@ -0,0 +1,5 @@
3 val <bold>x = 1</bold>
5 val <bold>y = x</bold>
8 val <bold>y = x</bold>
10 val <bold>z: Int</bold>
19 fun bar(<bold>m: Int</bold>) {
+9
View File
@@ -0,0 +1,9 @@
// FLOW: OUT
fun test(m: Int, <caret>n: Int) {
val x = when (m) {
1 -> 1
2 -> n
else -> 0
}
}
@@ -0,0 +1,2 @@
3 fun test(m: Int, <bold>n: Int</bold>) {
4 val <bold>x = when (m) {</bold>