From 0c6066db74f282f729646bde8e3538ebbed10a73 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Wed, 21 Apr 2021 13:28:30 +0300 Subject: [PATCH] [KAPT] Don't fail on illegal delegate Kapt ignores error diagnostics, but backend can't compile such code at all This is workaround so backend won't fail. #KT-46176 Fixed --- .../kotlin/codegen/JvmRuntimeTypes.kt | 8 ++- ...ileToSourceStubConverterTestGenerated.java | 5 ++ ...ileToSourceStubConverterTestGenerated.java | 5 ++ .../testData/converter/incorrectDelegate.kt | 19 +++++++ .../testData/converter/incorrectDelegate.txt | 54 +++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt create mode 100644 plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt index 41300265001..5af9015f9be 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt @@ -188,6 +188,12 @@ class JvmRuntimeTypes( else -> if (isMutable) mutablePropertyReferences else propertyReferences } - return classes[arity].defaultType + return if (arity >= 0) { + classes[arity].defaultType + } else { + //in case of ErrorUtils.ERROR_PROPERTY there would be no dispatchReceiverParameter and arity becomes negative + //so we just take zero argument reference class (because it is incorrect anyway) + classes[0].defaultType + } } } diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java index e72dfde7dbb..ba5bb42e02c 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/ClassFileToSourceStubConverterTestGenerated.java @@ -209,6 +209,11 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi runTest("plugins/kapt3/kapt3-compiler/testData/converter/importsKt22083.kt"); } + @TestMetadata("incorrectDelegate.kt") + public void testIncorrectDelegate() throws Exception { + runTest("plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt"); + } + @TestMetadata("inheritanceSimple.kt") public void testInheritanceSimple() throws Exception { runTest("plugins/kapt3/kapt3-compiler/testData/converter/inheritanceSimple.kt"); diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/IrClassFileToSourceStubConverterTestGenerated.java b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/IrClassFileToSourceStubConverterTestGenerated.java index 425e0e5a795..7b4ddb11eb1 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/IrClassFileToSourceStubConverterTestGenerated.java +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/IrClassFileToSourceStubConverterTestGenerated.java @@ -210,6 +210,11 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla runTest("plugins/kapt3/kapt3-compiler/testData/converter/importsKt22083.kt"); } + @TestMetadata("incorrectDelegate.kt") + public void testIncorrectDelegate() throws Exception { + runTest("plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt"); + } + @TestMetadata("inheritanceSimple.kt") public void testInheritanceSimple() throws Exception { runTest("plugins/kapt3/kapt3-compiler/testData/converter/inheritanceSimple.kt"); diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt b/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt new file mode 100644 index 00000000000..21948c12a71 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.kt @@ -0,0 +1,19 @@ +class HomeFragment { + @Suppress("TOO_MANY_ARGUMENTS", "DELEGATE_SPECIAL_FUNCTION_MISSING") + private val categoryNewsListPresenter by moxyPresenter { + + } + + private val groupedNewsListAdapter: GroupedNewsListDelegateAdapter by lazy { + GroupedNewsListDelegateAdapter( + categoryNewsListPresenter::onWiFiClick + ) + } +} + +class GroupedNewsListDelegateAdapter(onWiFiClickListener: () -> Unit) + + +fun moxyPresenter() { + +} diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.txt b/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.txt new file mode 100644 index 00000000000..179614a37a9 --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/incorrectDelegate.txt @@ -0,0 +1,54 @@ +import java.lang.System; + +@kotlin.Metadata() +public final class GroupedNewsListDelegateAdapter { + + public GroupedNewsListDelegateAdapter(@org.jetbrains.annotations.NotNull() + kotlin.jvm.functions.Function0 onWiFiClickListener) { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public final class HomeFragment { + private final kotlin.Unit categoryNewsListPresenter$delegate = null; + private final kotlin.Lazy groupedNewsListAdapter$delegate = null; + + public HomeFragment() { + super(); + } + + private final error.NonExistentClass getCategoryNewsListPresenter() { + return null; + } + + @kotlin.Suppress(names = {"TOO_MANY_ARGUMENTS", "DELEGATE_SPECIAL_FUNCTION_MISSING"}) + @java.lang.Deprecated() + private static void getCategoryNewsListPresenter$annotations() { + } + + private final GroupedNewsListDelegateAdapter getGroupedNewsListAdapter() { + return null; + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public final class IncorrectDelegateKt { + + public IncorrectDelegateKt() { + super(); + } + + public static final void moxyPresenter() { + } +}