IDEA-162579 "Unrecognized invocation of <init>" when decompiling kotlin bytecode

master
Egor.Ushakov 8 years ago
parent 77d6c2906f
commit ee83b25d1d
  1. 7
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  2. 1
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  3. BIN
      testData/classes/pkg/TestKotlinConstructorKt.class
  4. 75
      testData/results/TestKotlinConstructorKt.dec
  5. 8
      testData/src/pkg/TestKotlinConstructor.kt

@ -306,7 +306,12 @@ public class InvocationExprent extends Exprent {
buf.append("this(");
}
else {
throw new RuntimeException("Unrecognized invocation of " + CodeConstants.INIT_NAME);
if (instance != null) {
buf.append(instance.toJava(indent, tracer)).append(".<init>(");
}
else {
throw new RuntimeException("Unrecognized invocation of " + CodeConstants.INIT_NAME);
}
}
}

@ -89,6 +89,7 @@ public class SingleClassesTest {
@Test public void testExtendingSubclass() { doTest("pkg/TestExtendingSubclass"); }
@Test public void testSyntheticAccess() { doTest("pkg/TestSyntheticAccess"); }
@Test public void testIllegalVarName() { doTest("pkg/TestIllegalVarName"); }
@Test public void testKotlinConstructor() { doTest("pkg/TestKotlinConstructorKt"); }
private void doTest(String testFile, String... companionFiles) {
ConsoleDecompiler decompiler = fixture.getDecompiler();

@ -0,0 +1,75 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.TypeCastException;
import kotlin.collections.CollectionsKt;
@Metadata(
mv = {1, 1, 1},
bv = {1, 0, 0},
k = 2,
d1 = {"\u0000\u0016\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u001e\n\u0002\u0010\u000e\n\u0000\u001a\u001c\u0010\u0000\u001a\b\u0012\u0004\u0012\u00020\u00020\u00012\f\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004H\u0002¨\u0006\u0006"},
d2 = {"foo", "", "LMapping;", "list", "", "", "module1"}
)
public final class TestKotlinConstructorKt {
private static final List<Mapping> foo(Collection<String> list) {
Iterable $receiver$iv = (Iterable)list;// 2
Collection destination$iv$iv = (Collection)(new ArrayList(CollectionsKt.collectionSizeOrDefault($receiver$iv, 10)));// 10
Iterator var4 = $receiver$iv.iterator();// 11
while(var4.hasNext()) {
Object item$iv$iv = var4.next();
String it = (String)item$iv$iv;// 12
Mapping var10000 = new Mapping;
if(it == null) {// 3
throw new TypeCastException("null cannot be cast to non-null type kotlin.String");
}
var10000.<init>((String)it);
Mapping var11 = var10000;
destination$iv$iv.add(var11);
}
return CollectionsKt.toList((Iterable)((List)destination$iv$iv));// 4 13
}
}
class 'TestKotlinConstructorKt' {
method 'foo (Ljava/util/Collection;)Ljava/util/List;' {
1 17
4 17
d 18
f 18
15 18
18 18
1b 19
20 19
24 21
2e 22
33 22
38 23
3b 23
46 25
4d 26
52 26
53 29
56 29
59 30
5f 31
69 34
6c 34
6f 34
72 34
}
}
Lines mapping:
2 <-> 18
3 <-> 26
4 <-> 35
10 <-> 19
11 <-> 20
12 <-> 24
13 <-> 35

@ -0,0 +1,8 @@
private fun foo(list: Collection<String>): List<Mapping> {
return list.map {
Mapping(it as String)
}.toList()
}
class Mapping(c: String) {
}
Loading…
Cancel
Save