Resolve invoke on class objects and enum entries

Added FakeCallableDescriptorForObject to make a resolved call
with object as variable in 'variable as function call'

 #KT-4321 Fixed
 #KT-4863 Fixed
This commit is contained in:
Svetlana Isakova
2014-07-18 18:58:03 +04:00
parent 19d35b8ec6
commit e4e09d6c70
34 changed files with 551 additions and 22 deletions
@@ -0,0 +1,8 @@
class A {
class object {
fun invoke(i: Int) = i
}
}
fun box() = if (A(42) == 42) "OK" else "fail"
@@ -0,0 +1,11 @@
trait B
fun B.invoke(i: Int) = i
class A {
class object: B {
}
}
fun box() = if (A(42) == 42) "OK" else "fail"
@@ -0,0 +1,9 @@
class A {
class Nested {
class object {
fun invoke(i: Int) = i
}
}
}
fun box() = if (A.Nested(42) == 42) "OK" else "fail"
@@ -0,0 +1,11 @@
import A.Nested
class A {
class Nested {
class object {
fun invoke(i: Int) = i
}
}
}
fun box() = if (Nested(42) == 42) "OK" else "fail"
@@ -0,0 +1,8 @@
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun box() = if (A.ONE(42) == 42) "OK" else "fail"
@@ -0,0 +1,8 @@
enum class A {
ONE
TWO
}
fun A.invoke(i: Int) = i
fun box() = if (A.ONE(42) == 42) "OK" else "fail"
@@ -0,0 +1,10 @@
import A.ONE
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun box() = if (ONE(42) == 42) "OK" else "fail"
@@ -0,0 +1,10 @@
import A.ONE
enum class A {
ONE
TWO
}
fun A.invoke(i: Int) = i
fun box() = if (ONE(42) == 42) "OK" else "fail"
@@ -0,0 +1,5 @@
object A
fun A.invoke(i: Int) = i
fun box() = if (A(42) == 42) "OK" else "fail"
@@ -0,0 +1,5 @@
object A {
fun invoke(i: Int) = i
}
fun box() = if (A(42) == 42) "OK" else "fail"
@@ -0,0 +1,35 @@
//KT-4321 invoke() on enum doesn't work
import DOMElementTestClasses.cls2
// use case 1
enum class DOMElementTestClasses {
cls1 cls2
fun invoke() {}
}
// use case 2
trait EnumStyleClass {
fun invoke() {}
}
enum class TestClasses : EnumStyleClass {
cls
}
// example
fun main(args: Array<String>) {
// Kotlin: Expression 'cls1' of type 'DOMElementTestClasses' cannot be invoked as a function
DOMElementTestClasses.cls1()
// Kotlin: Expression 'cls2' of type 'DOMElementTestClasses' cannot be invoked as a function
cls2()
// Kotlin: Expression 'cls' of type 'TestClasses' cannot be invoked as a function
TestClasses.cls()
// All ok
val cls = DOMElementTestClasses.cls2
cls()
}
@@ -0,0 +1,7 @@
class A {
class object {
fun invoke(i: Int) = i
}
}
fun test() = <caret>A(1)
@@ -0,0 +1,16 @@
class A {
class object {
fun invoke(i: Int) = i
}
}
fun test() = <caret>A(1)
Resolved call:
Resulting descriptor: class A
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
@@ -0,0 +1,7 @@
class A {
class object {
fun invoke(i: Int) = i
}
}
fun test() = A<caret>(1)
@@ -0,0 +1,20 @@
class A {
class object {
fun invoke(i: Int) = i
}
}
fun test() = A<caret>(1)
Resolved call:
Resulting descriptor: fun invoke(i: Int): Int
Explicit receiver kind = THIS_OBJECT
This object = A {<class-object-for-A>}
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS i : Int = 1
@@ -0,0 +1,8 @@
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun test() = A.<caret>ONE(1)
@@ -0,0 +1,17 @@
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun test() = A.<caret>ONE(1)
Resolved call:
Resulting descriptor: enum entry ONE : A
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
@@ -0,0 +1,8 @@
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun test() = A.ONE<caret>(1)
@@ -0,0 +1,21 @@
enum class A {
ONE
TWO
fun invoke(i: Int) = i
}
fun test() = A.ONE<caret>(1)
Resolved call:
Resulting descriptor: fun invoke(i: Int): Int
Explicit receiver kind = THIS_OBJECT
This object = ONE {A}
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS i : Int = 1
@@ -0,0 +1,5 @@
object A {
fun invoke(i: Int) = i
}
fun test() = <caret>A(1)
@@ -0,0 +1,14 @@
object A {
fun invoke(i: Int) = i
}
fun test() = <caret>A(1)
Resolved call:
Resulting descriptor: object A
Explicit receiver kind = NO_EXPLICIT_RECEIVER
This object = NO_RECEIVER
Receiver argument = NO_RECEIVER
@@ -0,0 +1,5 @@
object A {
fun invoke(i: Int) = i
}
fun test() = A<caret>(1)
@@ -0,0 +1,18 @@
object A {
fun invoke(i: Int) = i
}
fun test() = A<caret>(1)
Resolved call:
Resulting descriptor: fun invoke(i: Int): Int
Explicit receiver kind = THIS_OBJECT
This object = A {A}
Receiver argument = NO_RECEIVER
Value arguments mapping:
SUCCESS i : Int = 1