From ee83b25d1de324cd84c8fc750cb24a907e6f37c9 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Fri, 14 Oct 2016 14:40:00 +0300 Subject: [PATCH] IDEA-162579 "Unrecognized invocation of " when decompiling kotlin bytecode --- .../decompiler/exps/InvocationExprent.java | 7 +- .../java/decompiler/SingleClassesTest.java | 1 + .../classes/pkg/TestKotlinConstructorKt.class | Bin 0 -> 2124 bytes testData/results/TestKotlinConstructorKt.dec | 75 ++++++++++++++++++ testData/src/pkg/TestKotlinConstructor.kt | 8 ++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 testData/classes/pkg/TestKotlinConstructorKt.class create mode 100644 testData/results/TestKotlinConstructorKt.dec create mode 100644 testData/src/pkg/TestKotlinConstructor.kt diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index 94c1b5d..5b2ffbd 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -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(".("); + } + else { + throw new RuntimeException("Unrecognized invocation of " + CodeConstants.INIT_NAME); + } } } diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index d571281..48e8b7d 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -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(); diff --git a/testData/classes/pkg/TestKotlinConstructorKt.class b/testData/classes/pkg/TestKotlinConstructorKt.class new file mode 100644 index 0000000000000000000000000000000000000000..28766ddcedf80efbaa7dfb3654228025fa6a41a2 GIT binary patch literal 2124 zcmbVNT~`}b6x}xoOqc`;lv09NV~H5T=cJ--f*|tIMgr6ZQA!nuWS~>R3~Oe>qCWL+ z_zU#WH;OEk<%?_iqr`nD2}zN@xYlHH?m6e4v+q9V-1+;TUw;RX#`glZ*A3TOw!N}x z&D)miIhCSkJIkH|A<+3kKhh`4y0tg4w)4U$QX3Qq?%K9MGMV?S70)bB%-iKM&8BT- zhnv)S)Ah0f-Hk9g&v5jevY|i`xY-CW=Q#RH>8_wnAinPdnkZg|b(>PS5?zGQ8|H%f zgR$l;7`u9<>x*#NvO|8aT|RRgb}Ns+b5`QSMZL2@?3XUjbj20CWoI!@hs~zZbSA!^^Cd`DM&=Lpwp@7Iy!BQS1%p*Q;Zm9tkxRG#-qG28xPTj4iDe@&C zfvyr~$h36HZr!!FX$%@o#9@#?b|s8;4pFo@1>37`V<(h-4!ZKSGOie&UeZ0C5dsHC zL5?ryGqB@J;EDF7DnM096PP`J)vKPrQUjfFHP9ERig&o|px8gq$yc~L)E$@%Op0{0 zGgw=-Ooko>{`|SMRfb6mra)W1)>F)@9N48w*YcGxQeUcxVw@Zd3)Gq4f4c#&2 zw6Dt-3C)|9v06FUF`SyFz2ND^eWs|b+Y06$d8|0}et7)_Gu>2!T6JgsbLmW9!k&?o z7wn2tG?q*WqNlo8Fm@_?i^rZ}xvZK%>`BG)%mZV?bWMVtlY`+G)MdK{5F)#hkAAeE zmFus$IHVM%)=ixwoX5z@8Pv^@PW3f9PtbFY-c^jAqF*2riiJ)Q7x)pgQc6(OG8St& z$55sVjP04@kA zaz(2kq+p1Fr>xOF$%N{qST0Z8{rYqAMS&?d|3r43f&L+MqW2Afu_8c7JLxozW&$ zEj>kP^j=2O)YM`Fs^6q)>VM*8s`Q{H foo(Collection 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.((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 diff --git a/testData/src/pkg/TestKotlinConstructor.kt b/testData/src/pkg/TestKotlinConstructor.kt new file mode 100644 index 0000000..cb9a363 --- /dev/null +++ b/testData/src/pkg/TestKotlinConstructor.kt @@ -0,0 +1,8 @@ +private fun foo(list: Collection): List { + return list.map { + Mapping(it as String) + }.toList() +} + +class Mapping(c: String) { +}