[AA] Add tests for *static* (declared) member scopes

^KT-61900
^KT-61800
This commit is contained in:
Marco Pennekamp
2023-09-13 21:15:01 +02:00
committed by Space Team
parent 4ba0aef23b
commit 21efd6aff3
32 changed files with 1627 additions and 0 deletions
@@ -0,0 +1,31 @@
package test
abstract class A {
fun perform() { }
val x: Int = 0
class C1
object O1
companion object {
val y: Int = 0
}
}
class C : A() {
fun foo(): Int = 5
val bar: String = ""
class C2
object O2
companion object {
val baz: String = ""
}
}
// class: test/C
@@ -0,0 +1,5 @@
class C2
object O2
companion object
@@ -0,0 +1,86 @@
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/C.C2
classKind: CLASS
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: C2
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/C.O2
classKind: OBJECT
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: O2
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/C.Companion
classKind: COMPANION_OBJECT
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: Companion
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
@@ -0,0 +1,37 @@
// class: test/KotlinClass
// FILE: JavaClass.java
package test
public abstract class JavaClass {
public void perform() {
}
public int x = 0;
public static void hello() {
}
public static int y = 1;
public class C1 {
}
}
// FILE: KotlinClass.kt
package test
// When a java class inherits from `JavaClass`, its static member scope contains `hello` and `y`. However, when a Kotlin class inherits from
// `JavaClass`, like this class, its static member scope does not contain the Java super-class's static callables.
class KotlinClass : JavaClass() {
fun foo(): Int = 5
val bar: String = ""
class C2
object O2
companion object {
val baz: String = ""
}
}
@@ -0,0 +1,5 @@
class C2
object O2
companion object
@@ -0,0 +1,86 @@
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/KotlinClass.C2
classKind: CLASS
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: C2
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/KotlinClass.O2
classKind: OBJECT
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: O2
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: test/KotlinClass.Companion
classKind: COMPANION_OBJECT
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: Companion
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null
@@ -0,0 +1,10 @@
package test
enum class E {
A {
val x: String = ""
},
B
}
// class: test/E
@@ -0,0 +1,9 @@
A
B
fun values(): kotlin.Array<test.E>
fun valueOf(value: kotlin.String): test.E
val entries: kotlin.enums.EnumEntries<test.E>
@@ -0,0 +1,200 @@
KtEnumEntrySymbol:
annotationsList: []
callableIdIfNonLocal: test/E.A
containingEnumClassIdIfNonLocal: test/E
contextReceivers: []
enumEntryInitializer: KtAnonymousObjectSymbol(<local>/<no name provided>)
isExtension: false
name: A
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
symbolKind: CLASS_MEMBER
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtEnumEntrySymbol:
annotationsList: []
callableIdIfNonLocal: test/E.B
containingEnumClassIdIfNonLocal: test/E
contextReceivers: []
enumEntryInitializer: null
isExtension: false
name: B
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
symbolKind: CLASS_MEMBER
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: test/E.values
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isActual: false
isBuiltinFunctionInvoke: false
isExpect: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: true
isSuspend: false
modality: FINAL
name: values
origin: SOURCE_MEMBER_GENERATED
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
]
type: kotlin/Array<test/E>
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: test/E.valueOf
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isActual: false
isBuiltinFunctionInvoke: false
isExpect: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: true
isSuspend: false
modality: FINAL
name: valueOf
origin: SOURCE_MEMBER_GENERATED
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: value
origin: SOURCE_MEMBER_GENERATED
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
]
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtKotlinPropertySymbol:
annotationsList: []
backingFieldSymbol: null
callableIdIfNonLocal: test/E.entries
contextReceivers: []
getter: KtPropertyGetterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
hasBody: false
hasStableParameterNames: true
isDefault: true
isExtension: false
isInline: false
isOverride: false
modality: FINAL
origin: SOURCE_MEMBER_GENERATED
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
]
type: kotlin/enums/EnumEntries<test/E>
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
hasBackingField: false
hasGetter: true
hasSetter: false
initializer: null
isActual: false
isConst: false
isDelegatedProperty: false
isExpect: false
isExtension: false
isFromPrimaryConstructor: false
isLateInit: false
isOverride: false
isStatic: true
isVal: true
modality: FINAL
name: entries
origin: SOURCE_MEMBER_GENERATED
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: test/E
]
type: kotlin/enums/EnumEntries<test/E>
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
getterDeprecationStatus: null
javaGetterName: getEntries
javaSetterName: null
setterDeprecationStatus: null
@@ -0,0 +1,50 @@
// class: JavaClass
// FILE: main.kt
// FILE: SuperInterface.java
public interface SuperInterface {
public int getActualRandomNumber();
// This static method will not be included in JavaClass's static member scope, because static interface methods are not propagated to
// their implementing class's namespaces (i.e., `JavaClass.getRandomNumber()` is an error in Kotlin and Java).
public static int getRandomNumber() {
return 3; // Decided by a fair dice roll.
}
}
// FILE: SuperClass.java
public abstract class SuperClass implements SuperInterface {
// NestedSuperClass will not be included in JavaClass's static member scope, because Kotlin does not propagate static nested classes
// defined in super-classes to sub-classes, unlike Java. So `JavaClass.SuperClass` is valid in Java, but an error in Kotlin.
class NestedSuperClass {
}
@Override
public int getActualRandomNumber() {
return getRandomNumber();
}
// Both static callables will be included in JavaClass's static member scope, because Kotlin propagates static methods from
// super-classes to sub-classes, just like Java. So `JavaClass.superBar()` will be a valid call in Kotlin and Java.
public static int superFoo = 5;
public static String superBar() {
return "superBar";
}
}
// FILE: JavaClass.java
public class JavaClass extends SuperClass {
class NestedClass {
}
public static int foo = 1;
public static String bar() {
return "bar";
}
public void hello() {
System.out.println("hello");
}
}
@@ -0,0 +1,9 @@
open fun bar(): kotlin.String!
open var superFoo: kotlin.Int
open fun superBar(): kotlin.String!
open var foo: kotlin.Int
open inner class NestedClass
@@ -0,0 +1,132 @@
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.bar
contextReceivers: []
contractEffects: []
hasStableParameterNames: false
isActual: false
isBuiltinFunctionInvoke: false
isExpect: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: true
isSuspend: false
modality: OPEN
name: bar
origin: JAVA
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/String!
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtJavaFieldSymbol:
annotationsList: []
callableIdIfNonLocal: /SuperClass.superFoo
contextReceivers: []
isExtension: false
isStatic: true
isVal: false
modality: OPEN
name: superFoo
origin: JAVA
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /SuperClass.superBar
contextReceivers: []
contractEffects: []
hasStableParameterNames: false
isActual: false
isBuiltinFunctionInvoke: false
isExpect: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: true
isSuspend: false
modality: OPEN
name: superBar
origin: JAVA
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/String!
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtJavaFieldSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.foo
contextReceivers: []
isExtension: false
isStatic: true
isVal: false
modality: OPEN
name: foo
origin: JAVA
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: JavaClass.NestedClass
classKind: CLASS
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: true
modality: OPEN
name: NestedClass
origin: JAVA
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: PackageVisibility
getContainingModule: KtSourceModule "Sources of main"
annotationApplicableTargets: null
deprecationStatus: null