KT-1892: initializers for extension properties
This commit is contained in:
@@ -223,22 +223,19 @@ public class NamespaceCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public void doSomething(@NotNull ClassBuilder v) {
|
public void doSomething(@NotNull ClassBuilder v) {
|
||||||
MethodVisitor mv = v.newMethod(namespace, ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
MethodVisitor mv = v.newMethod(namespace, ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
||||||
for (JetFile file : files) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
mv.visitCode();
|
||||||
mv.visitCode();
|
|
||||||
|
|
||||||
FrameMap frameMap = new FrameMap();
|
FrameMap frameMap = new FrameMap();
|
||||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, CodegenContexts.STATIC, state);
|
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, CodegenContexts.STATIC, state);
|
||||||
|
|
||||||
|
for (JetFile file : files) {
|
||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
||||||
if (initializer != null && !(initializer instanceof JetConstantExpression)) {
|
if (initializer != null && !(initializer instanceof JetConstantExpression)) {
|
||||||
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, declaration);
|
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, declaration);
|
||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
if (descriptor.getReceiverParameter().exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
codegen.genToJVMStack(initializer);
|
codegen.genToJVMStack(initializer);
|
||||||
StackValue.Property propValue = codegen.intermediateValueForProperty(descriptor, true, null);
|
StackValue.Property propValue = codegen.intermediateValueForProperty(descriptor, true, null);
|
||||||
propValue.store(propValue.type, new InstructionAdapter(mv));
|
propValue.store(propValue.type, new InstructionAdapter(mv));
|
||||||
@@ -246,9 +243,7 @@ public class NamespaceCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
FunctionCodegen.endVisit(mv, "static initializer for namespace", namespace);
|
FunctionCodegen.endVisit(mv, "static initializer for namespace", namespace);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
val Int.ext : () -> Int = { 5 }
|
||||||
|
val Long.ext : Long = 4.ext().toLong() //(c.kt:4)
|
||||||
|
val y : Long = 10.toLong().ext
|
||||||
|
|
||||||
|
fun box() : String = if (y == 5.toLong()) "OK" else "fail"
|
||||||
@@ -232,6 +232,12 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
blackBoxFile("regressions/kt2331.kt");
|
blackBoxFile("regressions/kt2331.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt1892() throws Exception {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("regressions/kt1892.kt");
|
||||||
|
//System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
|
||||||
public void testKt1846() throws Exception {
|
public void testKt1846() throws Exception {
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
loadFile("regressions/kt1846.kt");
|
loadFile("regressions/kt1846.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user