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>