From ea69d26bace90ae8e7621d9d0e9868ea5386019a Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 17 Sep 2018 12:56:54 +0300 Subject: [PATCH] Don't throw exception on error types in light classes mode #KT-26829 Fixed #KT-26827 Fixed --- .../codegen/state/KotlinTypeMapper.java | 22 +++++++++++-------- .../dataInlineClassDeclaration.kt | 6 +++++ .../unusedSymbol/propertyOfInlineClassType.kt | 5 +++++ .../LocalInspectionTestGenerated.java | 10 +++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 idea/testData/inspectionsLocal/unusedSymbol/dataInlineClassDeclaration.kt create mode 100644 idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 1e3b996fe70..a634ac55f22 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -509,31 +509,35 @@ public class KotlinTypeMapper { ); } + // Make sure this method is called only from back-end + // It uses staticTypeMappingConfiguration that throws exception on error types @NotNull public static Type mapInlineClassTypeAsDeclaration(@NotNull KotlinType kotlinType) { - return mapInlineClassType(kotlinType, TypeMappingMode.CLASS_DECLARATION); + return mapInlineClassType(kotlinType, TypeMappingMode.CLASS_DECLARATION, staticTypeMappingConfiguration); } + // Make sure this method is called only from back-end + // It uses staticTypeMappingConfiguration that throws exception on error types @NotNull public static Type mapUnderlyingTypeOfInlineClassType(@NotNull KotlinType kotlinType) { KotlinType underlyingType = InlineClassesUtilsKt.unsubstitutedUnderlyingType(kotlinType); if (underlyingType == null) { throw new IllegalStateException("There should be underlying type for inline class type: " + kotlinType); } - return mapInlineClassType(underlyingType, TypeMappingMode.DEFAULT); + return mapInlineClassType(underlyingType, TypeMappingMode.DEFAULT, staticTypeMappingConfiguration); } - @NotNull - public static Type mapInlineClassType(@NotNull KotlinType kotlinType) { - return mapInlineClassType(kotlinType, TypeMappingMode.DEFAULT); + private Type mapInlineClassType(@NotNull KotlinType kotlinType) { + return mapInlineClassType(kotlinType, TypeMappingMode.DEFAULT, typeMappingConfiguration); } private static Type mapInlineClassType( @NotNull KotlinType kotlinType, - @NotNull TypeMappingMode mode + @NotNull TypeMappingMode mode, + @NotNull TypeMappingConfiguration configuration ) { return TypeSignatureMappingKt.mapType( - kotlinType, AsmTypeFactory.INSTANCE, mode, staticTypeMappingConfiguration, null, + kotlinType, AsmTypeFactory.INSTANCE, mode, configuration, null, (ktType, asmType, typeMappingMode) -> Unit.INSTANCE, false ); @@ -1400,7 +1404,7 @@ public class KotlinTypeMapper { * In that case the generated method's return type should be boxed: otherwise it's not possible to use * this class from Java since javac issues errors when loading the class (incompatible return types) */ - private static boolean forceBoxedReturnType(@NotNull FunctionDescriptor descriptor) { + private boolean forceBoxedReturnType(@NotNull FunctionDescriptor descriptor) { if (isBoxMethodForInlineClass(descriptor)) return true; //noinspection ConstantConditions @@ -1414,7 +1418,7 @@ public class KotlinTypeMapper { return false; } - private static boolean isJvmPrimitive(@NotNull KotlinType kotlinType) { + private boolean isJvmPrimitive(@NotNull KotlinType kotlinType) { if (KotlinBuiltIns.isPrimitiveType(kotlinType)) return true; if (InlineClassesUtilsKt.isInlineClassType(kotlinType) && !KotlinTypeKt.isError(kotlinType)) { diff --git a/idea/testData/inspectionsLocal/unusedSymbol/dataInlineClassDeclaration.kt b/idea/testData/inspectionsLocal/unusedSymbol/dataInlineClassDeclaration.kt new file mode 100644 index 00000000000..c2321ade4b0 --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/dataInlineClassDeclaration.kt @@ -0,0 +1,6 @@ +// PROBLEM: none +// ERROR: Modifier 'data' is incompatible with 'inline' +// ERROR: Modifier 'inline' is incompatible with 'data' +// ERROR: Unresolved reference: Unresolved + +data inline class Foo(val x: Unresolved) \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt b/idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt new file mode 100644 index 00000000000..10ed9d49d58 --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt @@ -0,0 +1,5 @@ +// WITH_RUNTIME +// PROBLEM: none + +inline class Inline(val x1: UInt) +class WrapInline(val x2: Inline) \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index cbcc018f320..464a2816217 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -6178,6 +6178,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/unusedSymbol/companionViaImport.kt"); } + @TestMetadata("dataInlineClassDeclaration.kt") + public void testDataInlineClassDeclaration() throws Exception { + runTest("idea/testData/inspectionsLocal/unusedSymbol/dataInlineClassDeclaration.kt"); + } + @TestMetadata("inAnonymous.kt") public void testInAnonymous() throws Exception { runTest("idea/testData/inspectionsLocal/unusedSymbol/inAnonymous.kt"); @@ -6198,6 +6203,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/unusedSymbol/internal.kt"); } + @TestMetadata("propertyOfInlineClassType.kt") + public void testPropertyOfInlineClassType() throws Exception { + runTest("idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt"); + } + @TestMetadata("withJvmNameUsedFromKotlin.kt") public void testWithJvmNameUsedFromKotlin() throws Exception { runTest("idea/testData/inspectionsLocal/unusedSymbol/withJvmNameUsedFromKotlin.kt");