Report error when try to access to static field which come from many sources
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// FILE: A.java
|
||||
|
||||
public interface A {
|
||||
int field = 1;
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
public interface B {
|
||||
String field = 1;
|
||||
}
|
||||
|
||||
// FILE: E.java
|
||||
|
||||
public class E implements A, B {
|
||||
}
|
||||
|
||||
// FILE: O.java
|
||||
|
||||
public class O implements A, B {
|
||||
public static double field = 1;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
A.field
|
||||
B.field
|
||||
|
||||
E.<!OVERLOAD_RESOLUTION_AMBIGUITY!>field<!>
|
||||
O.field
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public interface 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
|
||||
|
||||
// Static members
|
||||
public const final val field: kotlin.Int = 1
|
||||
}
|
||||
|
||||
public interface 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class E : A, B {
|
||||
public constructor E()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.Int
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class O : A, B {
|
||||
public constructor O()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final override /*2*/ var field: kotlin.Double
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// FILE: A.java
|
||||
|
||||
public interface A {
|
||||
int field = 1;
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
public interface B extends A {
|
||||
String field = 1;
|
||||
}
|
||||
|
||||
// FILE: E.java
|
||||
|
||||
public class E implements A, B {
|
||||
}
|
||||
|
||||
// FILE: O.java
|
||||
|
||||
public class O implements A, B {
|
||||
public static double field = 1;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
A.field
|
||||
B.field
|
||||
|
||||
E.<!OVERLOAD_RESOLUTION_AMBIGUITY!>field<!>
|
||||
O.field
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public interface 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
|
||||
|
||||
// Static members
|
||||
public const final val field: kotlin.Int = 1
|
||||
}
|
||||
|
||||
public interface B : 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
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class E : A, B {
|
||||
public constructor E()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.Int
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class O : A, B {
|
||||
public constructor O()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final override /*2*/ var field: kotlin.Double
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// FILE: A.java
|
||||
|
||||
public interface A {
|
||||
int field = 1;
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
public interface B {
|
||||
String field = 1;
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
|
||||
public interface C extends A {
|
||||
}
|
||||
|
||||
// FILE: D.java
|
||||
|
||||
public interface D extends B {
|
||||
}
|
||||
|
||||
// FILE: E.java
|
||||
|
||||
public class E implements C, D {
|
||||
}
|
||||
|
||||
// FILE: EE.java
|
||||
|
||||
public class EE extends E {
|
||||
}
|
||||
|
||||
// FILE: EO.java
|
||||
|
||||
public class EO extends E {
|
||||
public static double field = 1;
|
||||
}
|
||||
|
||||
// FILE: O.java
|
||||
|
||||
public class O implements C, D {
|
||||
public static double field = 1;
|
||||
}
|
||||
|
||||
// FILE: OO.java
|
||||
|
||||
public class OO extends O {
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
A.field
|
||||
B.field
|
||||
|
||||
C.field
|
||||
D.field
|
||||
|
||||
E.<!OVERLOAD_RESOLUTION_AMBIGUITY!>field<!>
|
||||
O.field
|
||||
|
||||
EE.<!OVERLOAD_RESOLUTION_AMBIGUITY!>field<!>
|
||||
EO.field
|
||||
|
||||
OO.field
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public interface 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
|
||||
|
||||
// Static members
|
||||
public const final val field: kotlin.Int = 1
|
||||
}
|
||||
|
||||
public interface 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final val field: kotlin.String
|
||||
}
|
||||
|
||||
public interface C : 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
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.Int
|
||||
}
|
||||
|
||||
public interface D : 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class E : C, D {
|
||||
public constructor E()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.Int
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class EE : E {
|
||||
public constructor EE()
|
||||
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 const final override /*1*/ /*fake_override*/ val field: kotlin.Int
|
||||
public const final override /*1*/ /*fake_override*/ val field: kotlin.String
|
||||
}
|
||||
|
||||
public open class EO : E {
|
||||
public constructor EO()
|
||||
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 final override /*2*/ var field: kotlin.Double
|
||||
}
|
||||
|
||||
public open class O : C, D {
|
||||
public constructor O()
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final override /*2*/ var field: kotlin.Double
|
||||
}
|
||||
|
||||
public open class OO : O {
|
||||
public constructor OO()
|
||||
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 final override /*1*/ /*fake_override*/ var field: kotlin.Double
|
||||
}
|
||||
@@ -12934,6 +12934,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nameClash0.kt")
|
||||
public void testNameClash0() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nameClash1.kt")
|
||||
public void testNameClash1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nameClash2.kt")
|
||||
public void testNameClash2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/nameClash2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("oneInterfaceManyTimes.kt")
|
||||
public void testOneInterfaceManyTimes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/statics/oneInterfaceManyTimes.kt");
|
||||
|
||||
+21
-1
@@ -85,7 +85,20 @@ public class LazyJavaStaticClassScope(
|
||||
|
||||
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
||||
val propertiesFromSupertypes = getStaticPropertiesFromJavaSupertypes(name, getContainingDeclaration())
|
||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter))
|
||||
|
||||
val actualProperties =
|
||||
if (!result.isEmpty()) {
|
||||
DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter)
|
||||
}
|
||||
else {
|
||||
propertiesFromSupertypes.groupBy {
|
||||
it.realOriginal
|
||||
}.flatMap {
|
||||
DescriptorResolverUtils.resolveOverrides(name, it.value, result, getContainingDeclaration(), c.components.errorReporter)
|
||||
}
|
||||
}
|
||||
|
||||
result.addAll(actualProperties)
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyJavaClassDescriptor
|
||||
@@ -114,4 +127,11 @@ public class LazyJavaStaticClassScope(
|
||||
|
||||
return descriptor.typeConstructor.supertypes.flatMap(::getStaticProperties).toSet()
|
||||
}
|
||||
|
||||
private val PropertyDescriptor.realOriginal: PropertyDescriptor
|
||||
get() {
|
||||
if (this.kind.isReal) return this
|
||||
|
||||
return this.overriddenDescriptors.map { it.realOriginal }.distinct().single()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user