rewrite owner when copying FunctionDescriptor from supertype scope

that fixes invocation:

>>> StringBuilder.length()

that was compiled to

>>> invokevirtual CharSequence.length()

and now compiles to

>>> invokevirtual StringBuilder.length()

Essentially patch rewrites FunctionDescriptor.containingDeclaration
when FunctionDescriptor is copied to subclass scope.

FunctionDescriptor now has kind field that can be
* DECLARATION (for "real" function, maybe abstract)
* DELEGATION
* FAKE_OVERRIDE (created for functions from supertypes)

All tests pass although some parts of code are buggy and ugly.

Random comments about this patch:

* FunctionDescriptor.overrides point to function descriptors of supertype scopes

* Filling of memberScope with supertypes is moved to OverrideResolver

* ExpressionCodegen.intermediateValueForProperty must be rewritten

* Patch adds not nice REDECLARATION reports (see compiler/testData/diagnostics/tests/*).
  Will be fixed later.
This commit is contained in:
Stepan Koltsov
2012-02-10 20:36:40 +04:00
parent 41455a56c5
commit 4b94eb5e2b
46 changed files with 814 additions and 325 deletions
@@ -12,7 +12,7 @@ class C() : B() {
this.b = 123
super.b = 23
<!VAL_REASSIGNMENT!>this.c<!> = 34
super.c = 3535 //repeat for 'c'
<!VAL_REASSIGNMENT!>super.c<!> = 3535 //repeat for 'c'
<!VARIABLE_EXPECTED!>getInt()<!> = 12
}
@@ -140,4 +140,4 @@ fun Array<Int>.checkThis() {
abstract class Ab {
abstract fun getArray() : Array<Int>
}
}
@@ -0,0 +1,9 @@
package override.generics
abstract class MyAbstractClass<T> {
abstract val <!REDECLARATION!>pr<!> : T
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyAbstractClass<Int>() {
val <R> <!REDECLARATION!>pr<!> : T = t
}
@@ -6,7 +6,7 @@ trait MyTrait<T> {
abstract class MyAbstractClass<T> {
abstract fun bar(t: T) : T
abstract val pr : T
abstract val <!REDECLARATION, REDECLARATION, REDECLARATION!>pr<!> : T
}
trait MyProps<T> {
@@ -43,7 +43,7 @@ abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r
<!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r
<!NOTHING_TO_OVERRIDE!>override<!> val <T> <!REDECLARATION!>pr<!> : R = r
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String>() {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
@@ -51,10 +51,10 @@ abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
val <R> <!REDECLARATION!>pr<!> : T = t
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
val <R> <!REDECLARATION!>pr<!> : T = t
}
@@ -0,0 +1,12 @@
// NamedFunctionDescriptor.substitute substitutes "overrides"
// this test checks it does it properly
trait Foo<P> {
fun quux(p: P, q: Int = 17) = 18
}
trait Bar<Q> : Foo<Q>
abstract class Baz() : Bar<String>
fun zz(b: Baz) = b.quux("a")