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 0000000..28766dd Binary files /dev/null and b/testData/classes/pkg/TestKotlinConstructorKt.class differ diff --git a/testData/results/TestKotlinConstructorKt.dec b/testData/results/TestKotlinConstructorKt.dec new file mode 100644 index 0000000..f032804 --- /dev/null +++ b/testData/results/TestKotlinConstructorKt.dec @@ -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 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) { +}