Fixed multiple bugs in optimize imports for JS-target

#KT-13689 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-10-06 21:32:22 +03:00
parent 45cd4f1e29
commit b84260f39f
148 changed files with 599 additions and 373 deletions
@@ -0,0 +1,8 @@
package test1
public class MyClass {
}
public fun MyClass.get(i: Int): Int {
return 1
}
@@ -0,0 +1,4 @@
import test1.MyClass
import test1.get
val s = MyClass()[1]
@@ -0,0 +1,4 @@
import test1.MyClass
import test1.get
val s = MyClass()[1]
@@ -0,0 +1,15 @@
package dependency
class A {
fun f() {
}
val p: Int = 1
}
interface T {
fun f() {
}
val p: Int = 1
}
@@ -0,0 +1,14 @@
package test
import dependency.*
import dependency.A.f
import dependency.A.p
import dependency.T.f
import dependency.T.p
fun f(a: A, t: T) {
a.f()
a.p
t.f
t.p
}
@@ -0,0 +1,11 @@
package test
import dependency.A
import dependency.T
fun f(a: A, t: T) {
a.f()
a.p
t.f
t.p
}
@@ -0,0 +1,7 @@
package test1
public class MyClass {
}
public fun MyClass.component1() = 1
public fun MyClass.component2() = 2
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.component1
import test1.component2
fun foo() {
val (a, b) = MyClass()
}
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.component1
import test1.component2
fun foo() {
val (a, b) = MyClass()
}
@@ -0,0 +1,3 @@
package ppp.ppp1
class C1
@@ -0,0 +1,8 @@
package ppp
import ppp.*
open class C
class D : C()
class E : ppp.ppp1.C1()
@@ -0,0 +1,6 @@
package ppp
open class C
class D : C()
class E : ppp.ppp1.C1()
@@ -0,0 +1,13 @@
package d
class A {
companion object E {
val c: Int
}
}
class B {
companion object F {
val c: Int
}
}
@@ -0,0 +1,11 @@
package p
import d.A
import d.A.E
import d.B.F
import d.B
fun main(args: Array<String>) {
F.c
A.c
}
@@ -0,0 +1,9 @@
package p
import d.A
import d.B.F
fun main(args: Array<String>) {
F.c
A.c
}
@@ -0,0 +1,16 @@
package dependency
class D {
enum class E1 {
E11,
E12
}
enum class E2 {
E21,
E22
}
enum class E3 {
E31,
E32
}
}
+18
View File
@@ -0,0 +1,18 @@
package foo
import dependency.D
import dependency.D.E1
import dependency.D.E1.E11
import dependency.D.E1.E12
import dependency.D.E2
import dependency.D.E2.E21
import dependency.D.E2.E22
import dependency.D.E3
import dependency.D.E3.E31
import dependency.D.E3.E32
fun foo {
E11
D.E2.E22
E3.E31
}
@@ -0,0 +1,11 @@
package foo
import dependency.D
import dependency.D.E1.E11
import dependency.D.E3
fun foo {
E11
D.E2.E22
E3.E31
}
@@ -0,0 +1,6 @@
Additional checking of reference Getter: E2
Additional checking of reference KtSimpleNameReference: E2
Additional checking of reference Getter: E22
Additional checking of reference KtSimpleNameReference: E22
Additional checking of reference Getter: E31
Additional checking of reference KtSimpleNameReference: E31
@@ -0,0 +1,6 @@
package test1
public class MyClass {
}
public fun MyClass.invoke() {}
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.invoke
fun foo() {
val s = MyClass()
s()
}
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.invoke
fun foo() {
val s = MyClass()
s()
}
@@ -0,0 +1,15 @@
package test1
public class MyClass {
}
public fun MyClass.iterator(): Iterator<MyClass> {
return object: Iterator<MyClass> {
override fun next(): MyClass {
throw Exception()
}
override fun hasNext(): Boolean {
throw Exception()
}
}
}
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.iterator
fun foo() {
val s = MyClass()
for (i in s) {}
}
@@ -0,0 +1,7 @@
import test1.MyClass
import test1.iterator
fun foo() {
val s = MyClass()
for (i in s) {}
}
@@ -0,0 +1,6 @@
package bug.a
class A(val foo: MyFunction)
class MyFunction
operator fun MyFunction.invoke() = println("invoke convention")
+13
View File
@@ -0,0 +1,13 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
package bug.b
import bug.a.*
import bug.a.invoke
fun A.foo() = println("extension function")
fun main(args: Array<String>) {
val a = A(MyFunction())
a.foo()
}
@@ -0,0 +1,13 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
package bug.b
import bug.a.*
import bug.a.invoke
fun A.foo() = println("extension function")
fun main(args: Array<String>) {
val a = A(MyFunction())
a.foo()
}
@@ -0,0 +1,6 @@
Additional checking of reference KtInvokeFunctionReference: A(MyFunction())
Additional checking of reference KtInvokeFunctionReference: MyFunction()
Additional checking of reference KtInvokeFunctionReference: foo()
Changed resolve of KtInvokeFunctionReference: foo()
Additional checking of reference KtInvokeFunctionReference: println("extension function")
Trying to build import list again with import rules: +bug.a.invoke
@@ -0,0 +1,6 @@
package bug.a
class A(val foo: MyFunction)
class MyFunction
operator fun MyFunction.invoke() = println("invoke convention")
@@ -0,0 +1,15 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 10
package bug.b
import bug.a.*
fun A.foo() = println("extension function")
fun main(args: Array<String>) {
val func = MyFunction()
func()
val a = A(func)
a.foo()
}
@@ -0,0 +1,15 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 10
package bug.b
import bug.a.*
fun A.foo() = println("extension function")
fun main(args: Array<String>) {
val func = MyFunction()
func()
val a = A(func)
a.foo()
}
@@ -0,0 +1,3 @@
Additional checking of reference KtInvokeFunctionReference: foo()
Changed resolve of KtInvokeFunctionReference: foo()
Trying to build import list again with import rules: +bug.a.*
@@ -0,0 +1,5 @@
import kotlin.Any
fun foo(): Any {
throw UnsupportedOperationException()
}
@@ -0,0 +1,3 @@
fun foo(): Any {
throw UnsupportedOperationException()
}
+18
View File
@@ -0,0 +1,18 @@
package p
import p.Outer.Inner1
import p.Outer.Inner2
class Outer {
inner class Inner1
inner class Inner2
}
fun foo(p: Outer.() -> Unit){}
fun bar() {
foo {
fun Inner1.f() {}
Inner2()
}
}
@@ -0,0 +1,17 @@
package p
import p.Outer.Inner1
class Outer {
inner class Inner1
inner class Inner2
}
fun foo(p: Outer.() -> Unit){}
fun bar() {
foo {
fun Inner1.f() {}
Inner2()
}
}
@@ -0,0 +1,3 @@
Additional checking of reference Getter: Inner2
Additional checking of reference KtSimpleNameReference: Inner2
Additional checking of reference KtInvokeFunctionReference: Inner2()
@@ -0,0 +1,3 @@
package foo.`val`
class `var`
@@ -0,0 +1,3 @@
import foo.`val`.*
var v: `var`? = null
@@ -0,0 +1,3 @@
import foo.`val`.`var`
var v: `var`? = null
@@ -0,0 +1,12 @@
package test
import test.MyEnum.ONE
fun main(args: Array<String>) {
println(ONE)
}
public enum class MyEnum {
ONE
TWO
}
@@ -0,0 +1,12 @@
package test
import test.MyEnum.ONE
fun main(args: Array<String>) {
println(ONE)
}
public enum class MyEnum {
ONE
TWO
}
+11
View File
@@ -0,0 +1,11 @@
import MyClass.Companion.TEST
fun main() {
TEST
}
class MyClass {
companion object {
object TEST {}
}
}
@@ -0,0 +1,11 @@
import MyClass.Companion.TEST
fun main() {
TEST
}
class MyClass {
companion object {
object TEST {}
}
}
@@ -0,0 +1,18 @@
package dependency
object O {
fun foo(){}
fun bar(){}
}
enum class E1 {
A1, B1, C1
}
enum class E2 {
A2, B2, C2
}
enum class E3 {
A3, B3, C3
}
@@ -0,0 +1,18 @@
// NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS: 2
package test
import dependency.O.foo
import dependency.O.bar
import dependency.E1.A1
import dependency.E1.B1
import dependency.E2.A2
import dependency.E3.*
fun f() {
foo()
bar()
val v1 = A1
val v2 = B1
val v3 = A2
val v4 = A3
}
@@ -0,0 +1,17 @@
// NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS: 2
package test
import dependency.E1.*
import dependency.E2.A2
import dependency.E3.A3
import dependency.O.bar
import dependency.O.foo
fun f() {
foo()
bar()
val v1 = A1
val v2 = B1
val v3 = A2
val v4 = A3
}
@@ -0,0 +1,21 @@
import Outer.Nested
import Outer.ClassObjectNested
import Outer.C.Inner
import Outer.C.Inner2
class Outer {
class Nested
class C {
fun foo(p1: Nested, p2: ClassObjectNested, p3: Inner) { }
inner class Inner
inner class Inner2
}
companion object {
class ClassObjectNested
}
fun f(i: Inner2){}
}
@@ -0,0 +1,18 @@
import Outer.C.Inner2
class Outer {
class Nested
class C {
fun foo(p1: Nested, p2: ClassObjectNested, p3: Inner) { }
inner class Inner
inner class Inner2
}
companion object {
class ClassObjectNested
}
fun f(i: Inner2){}
}
@@ -0,0 +1,9 @@
package ppp
import ppp.Base.Nested
fun foo(p: Nested) {}
class Base {
class Nested
}
@@ -0,0 +1,9 @@
package ppp
import ppp.Base.Nested
fun foo(p: Nested) {}
class Base {
class Nested
}
@@ -0,0 +1,7 @@
package pack1
fun foo(o: Any){}
val u1 = 1
val u2 = 1
val u3 = 1
@@ -0,0 +1,7 @@
package pack2
fun foo(o: String){}
val v1 = 1
val v2 = 1
val v3 = 1
@@ -0,0 +1,15 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 3
import pack1.foo
import pack1.u1
import pack1.u2
import pack1.u3
import pack1.u4
import pack1.u5
import pack2.*
fun f() {
foo("")
v1 + v2 + v3
u1 + u2 + u3
}
@@ -0,0 +1,11 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 3
import pack1.*
import pack1.foo
import pack2.*
fun f() {
foo("")
v1 + v2 + v3
u1 + u2 + u3
}
@@ -0,0 +1,8 @@
Additional checking of reference Getter: foo
Additional checking of reference KtSimpleNameReference: foo
Changed resolve of KtSimpleNameReference: foo
Additional checking of reference KtInvokeFunctionReference: foo("")
Trying to build import list again with import rules: +pack1.foo, +pack2.*
Additional checking of reference Getter: foo
Additional checking of reference KtSimpleNameReference: foo
Additional checking of reference KtInvokeFunctionReference: foo("")
@@ -0,0 +1,3 @@
package p1
class A(p: Int)
@@ -0,0 +1,3 @@
package p2
class A(s: String)
@@ -0,0 +1,8 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
import p1.*
import p2.A
fun f() {
A(1)
A("")
}
@@ -0,0 +1,8 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
import p1.*
import p2.A
fun f() {
A(1)
A("")
}
@@ -0,0 +1,9 @@
Additional checking of reference Getter: A
Additional checking of reference Getter: A
Additional checking of reference KtSimpleNameReference: A
Changed resolve of KtSimpleNameReference: A
Additional checking of reference KtSimpleNameReference: A
Changed resolve of KtSimpleNameReference: A
Additional checking of reference KtInvokeFunctionReference: A("")
Additional checking of reference KtInvokeFunctionReference: A(1)
Trying to build import list again with import rules: +p2.A, +p1.*
@@ -0,0 +1,5 @@
import kotlin.Any
fun foo(): Any {
throw UnsupportedOperationException()
}
@@ -0,0 +1,3 @@
fun foo(): Any {
throw UnsupportedOperationException()
}