When in debugger context, access private companion object directly

This commit is contained in:
Dmitry Petrov
2018-06-26 12:40:33 +03:00
parent bef3d4ace2
commit 46a3f7420c
9 changed files with 89 additions and 6 deletions
@@ -2651,12 +2651,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
"Containing declaration of the companion object " + companionObjectDescriptor +
": expected a class, actual: " + hostClassDescriptor;
CodegenContext hostClassContext = context;
while (hostClassContext.getContextDescriptor() != hostClassDescriptor) {
hostClassContext = hostClassContext.getParentContext();
assert hostClassContext != null :
"Host class context for " + hostClassDescriptor + " not found in context hierarchy for " + context;
}
CodegenContext hostClassContext = context.findParentContextWithDescriptor(hostClassDescriptor);
assert hostClassContext != null :
"Host class context for " + hostClassDescriptor + " not found in context hierarchy for " + context;
hostClassContext.markCompanionObjectDescriptorWithAccessorRequired(companionObjectDescriptor);
@@ -159,6 +159,10 @@ public class JvmCodegenUtil {
return true;
}
if (isDebuggerContext(contextBeforeInline)) {
return true;
}
CodegenContext context = contextBeforeInline.getFirstCrossInlineOrNonInlineContext();
if (context.isInlineMethodContext()) {
// Inline method can be called from a nested class.
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
val test: String
init {
test = result
}
}
fun box() = Outer().test
@@ -0,0 +1,17 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
class Nested {
val test: String
init {
test = result
}
}
}
fun box() = Outer.Nested().test
@@ -14039,6 +14039,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlock.kt")
public void testPrivateCompanionObjectAccessedFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlock.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt");
@@ -14039,6 +14039,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlock.kt")
public void testPrivateCompanionObjectAccessedFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlock.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt");
@@ -14039,6 +14039,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlock.kt")
public void testPrivateCompanionObjectAccessedFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlock.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt");
@@ -13369,6 +13369,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlock.kt")
public void testPrivateCompanionObjectAccessedFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlock.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt");
@@ -12241,6 +12241,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromAnonymousObjectInNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlock.kt")
public void testPrivateCompanionObjectAccessedFromInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlock.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInitBlockOfNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInitBlockOfNestedClass.kt");
}
@TestMetadata("privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt")
public void testPrivateCompanionObjectAccessedFromInlineLambdaInNestedClass() throws Exception {
runTest("compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromInlineLambdaInNestedClass.kt");