From ce3b489fa9eb04155c97706bec753f5a22b35b3e Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 16 Nov 2018 12:33:06 +0300 Subject: [PATCH] Avoid using CheckSignatureAdapter in ultra-light classes --- .../codegen/signature/BothSignatureWriter.java | 17 +++++++++++++---- .../kotlin/asJava/classes/ultraLightUtils.kt | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/signature/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/signature/BothSignatureWriter.java index c0819f2a01b..eb0b5aa15a2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/signature/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/signature/BothSignatureWriter.java @@ -31,11 +31,16 @@ public class BothSignatureWriter extends JvmSignatureWriter { public enum Mode { METHOD(CheckSignatureAdapter.METHOD_SIGNATURE), CLASS(CheckSignatureAdapter.CLASS_SIGNATURE), - TYPE(CheckSignatureAdapter.TYPE_SIGNATURE); + TYPE(CheckSignatureAdapter.TYPE_SIGNATURE), + // Expected to be used only from light classes for type mapping + // It's needed because CheckSignatureAdapter.TYPE_SIGNATURE doesn't allow V (void) types. + // They're only allowed with CheckSignatureAdapter.METHOD_SIGNATURE after calling `visitReturnType` while in light classes, + // we only need to map distinct types + SKIP_CHECKS(null); - private final int asmType; + private final Integer asmType; - Mode(int asmType) { + Mode(Integer asmType) { this.asmType = asmType; } } @@ -46,7 +51,11 @@ public class BothSignatureWriter extends JvmSignatureWriter { private boolean generic = false; public BothSignatureWriter(@NotNull Mode mode) { - this.signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter); + this.signatureVisitor = + mode.asmType != null + ? new CheckSignatureAdapter(mode.asmType, signatureWriter) + : signatureWriter + ; } private final Stack visitors = new Stack<>(); diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt index a6df5f57c6f..91dbdadc02c 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt @@ -85,7 +85,7 @@ internal fun UltraLightSupport.mapType( psiContext: PsiElement, mapTypeToSignatureWriter: (KotlinTypeMapper, JvmSignatureWriter) -> Unit ): PsiType { - val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.TYPE) + val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.SKIP_CHECKS) mapTypeToSignatureWriter(typeMapper(this), signatureWriter) val signature = StringCharacterIterator(signatureWriter.toString())