Allow to use static members from companion object's parents
This commit is contained in:
+10
-1
@@ -123,15 +123,24 @@ class ClassResolutionScopesSupport(
|
||||
|
||||
val implicitReceiver: ReceiverParameterDescriptor?
|
||||
|
||||
val parentForNewScope: LexicalScope
|
||||
|
||||
if (withCompanionObject) {
|
||||
staticScopes.addIfNotNull(classDescriptor.companionObjectDescriptor?.unsubstitutedInnerClassesScope)
|
||||
implicitReceiver = classDescriptor.companionObjectDescriptor?.thisAsReceiverParameter
|
||||
|
||||
parentForNewScope = classDescriptor.companionObjectDescriptor?.let {
|
||||
it.getAllSuperclassesWithoutAny().asReversed().fold(parent) { scope, currentClass ->
|
||||
createInheritanceScope(parent = scope, ownerDescriptor = ownerDescriptor, classDescriptor = currentClass, withCompanionObject = false)
|
||||
}
|
||||
} ?: parent
|
||||
}
|
||||
else {
|
||||
implicitReceiver = null
|
||||
parentForNewScope = parent
|
||||
}
|
||||
|
||||
return LexicalChainedScope(parent, ownerDescriptor, false,
|
||||
return LexicalChainedScope(parentForNewScope, ownerDescriptor, false,
|
||||
implicitReceiver,
|
||||
LexicalScopeKind.CLASS_INHERITANCE,
|
||||
memberScopes = *staticScopes.toTypedArray(), isStaticScope = true)
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
open class A {
|
||||
companion object : J() {
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion : J {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public final class B : A {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test2(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun foo(): kotlin.Unit
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: J2.java
|
||||
public class J2 extends A {
|
||||
public static void boo() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
open class A {
|
||||
companion object : J() {
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
|
||||
class B : J2() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
boo()
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
foo()
|
||||
bar()
|
||||
boo()
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
boo()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
boo()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion : J {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public final class B : J2 {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test2(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun foo(): kotlin.Unit
|
||||
}
|
||||
|
||||
public open class J2 : A {
|
||||
public constructor J2()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun boo(): kotlin.Unit
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
open class A<T> : J() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
val a: Int = <!TYPE_MISMATCH!>baz()<!>
|
||||
val b: T = baz()
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
foo()
|
||||
bar()
|
||||
val a: Int = <!TYPE_MISMATCH!>baz()<!>
|
||||
val b: T = baz()
|
||||
}
|
||||
|
||||
fun baz(): T = null!!
|
||||
|
||||
companion object : A<Int>() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
val a: Int = baz()
|
||||
val b: <!UNRESOLVED_REFERENCE!>T<!> = baz()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
val a: Int = baz()
|
||||
val b: <!UNRESOLVED_REFERENCE!>T<!> = baz()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package
|
||||
|
||||
public open class A</*0*/ T> : J {
|
||||
public constructor A</*0*/ T>()
|
||||
public final fun baz(): T
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion : A<kotlin.Int> {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun baz(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun test1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun foo(): kotlin.Unit
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
class A {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
companion object : J() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion : J {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun foo(): kotlin.Unit
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
open class B : J() {
|
||||
fun baz() {}
|
||||
}
|
||||
|
||||
class A {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
}
|
||||
|
||||
companion object : B() {
|
||||
init {
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
}
|
||||
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion : B {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun baz(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public open class B : J {
|
||||
public constructor B()
|
||||
public final fun baz(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class J {
|
||||
public constructor J()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public open fun foo(): kotlin.Unit
|
||||
}
|
||||
@@ -14256,6 +14256,45 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/staticsFromjavaAfterKotlin.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class CompanionObject extends AbstractDiagnosticsTest {
|
||||
@TestMetadata("accessToStaticMembersOfParentClass.kt")
|
||||
public void testAccessToStaticMembersOfParentClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("accessToStaticMembersOfParentClassJKJ.kt")
|
||||
public void testAccessToStaticMembersOfParentClassJKJ() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/accessToStaticMembersOfParentClassJKJ.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInCompanionObject() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromContainingClass.kt")
|
||||
public void testInheritFromContainingClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromContainingClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromJava.kt")
|
||||
public void testInheritFromJava() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJava.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritFromJavaAfterKotlin.kt")
|
||||
public void testInheritFromJavaAfterKotlin() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/companionObject/inheritFromJavaAfterKotlin.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user