Fix header scope for secondary constructors
Add companion object's scope and nested classes #KT-6996 fixed
This commit is contained in:
+8
-4
@@ -277,20 +277,22 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
JetScope companionObjectAdapterScope = (companionObjectDescriptor != null) ? new CompanionObjectMixinScope(companionObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
"ScopeForMemberDeclarationResolution: " + getName(),
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
companionObjectAdapterScope,
|
||||
getCompanionObjectScope(),
|
||||
getStaticScope()
|
||||
);
|
||||
}
|
||||
|
||||
private JetScope getCompanionObjectScope() {
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
return (companionObjectDescriptor != null) ? new CompanionObjectMixinScope(companionObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForInitializerResolution() {
|
||||
@@ -346,6 +348,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
this,
|
||||
"ScopeForSecondaryConstructorHeaderResolution: " + getName(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
getCompanionObjectScope(),
|
||||
DescriptorUtils.getStaticNestedClassesScope(this),
|
||||
getStaticScope()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
class A(val result: Int) {
|
||||
companion object {
|
||||
fun foo(): Int = 1
|
||||
val prop = 2
|
||||
val C = 3
|
||||
}
|
||||
object B {
|
||||
fun bar(): Int = 4
|
||||
val prop = 5
|
||||
}
|
||||
object C {
|
||||
}
|
||||
|
||||
constructor() : this(foo() + prop + B.bar() + B.prop + C) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result
|
||||
if (result != 15) return "fail: $result"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): Int = 1
|
||||
val prop = 2
|
||||
val C = 3
|
||||
}
|
||||
object B {
|
||||
fun bar(): Int = 4
|
||||
val prop = 5
|
||||
}
|
||||
object C {
|
||||
}
|
||||
|
||||
constructor(x: Int) {}
|
||||
constructor() : this(foo() + prop + B.bar() + B.prop + C) {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package
|
||||
|
||||
internal final class A {
|
||||
public constructor A()
|
||||
public constructor A(/*0*/ x: 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal object B {
|
||||
private constructor B()
|
||||
internal final val prop: kotlin.Int = 5
|
||||
internal final fun bar(): 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal object C {
|
||||
private constructor C()
|
||||
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
|
||||
}
|
||||
|
||||
internal companion object Companion {
|
||||
private constructor Companion()
|
||||
internal final val C: kotlin.Int = 3
|
||||
internal final val prop: kotlin.Int = 2
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
internal final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -10587,6 +10587,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectScope.kt")
|
||||
public void testCompanionObjectScope() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/companionObjectScope.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("constructorCallType.kt")
|
||||
public void testConstructorCallType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt");
|
||||
|
||||
+6
@@ -6317,6 +6317,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class SecondaryConstructors extends AbstractBlackBoxCodegenTest {
|
||||
@TestMetadata("accessToCompanion.kt")
|
||||
public void testAccessToCompanion() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/accessToCompanion.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSecondaryConstructors() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/secondaryConstructors"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user