From de1fa40c7ea9ac716104f81e3de3fb9e691de4a2 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 3 Apr 2020 13:04:27 +0700 Subject: [PATCH] CodeInliner: fix KNPE #KT-22733 Fixed #KT-36225 Fixed #EA-206694 Fixed --- .../kotlin/idea/codeInliner/CodeInliner.kt | 4 ++-- .../typeArguments/kt36225.kt | 19 +++++++++++++++++++ .../typeArguments/kt36225.kt.after | 19 +++++++++++++++++++ .../inline/function/TypeArguments.kt | 11 +++++++++++ .../inline/function/TypeArguments.kt.after | 9 +++++++++ .../idea/quickfix/QuickFixTestGenerated.java | 5 +++++ .../inline/InlineTestGenerated.java | 5 +++++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt create mode 100644 idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt.after create mode 100644 idea/testData/refactoring/inline/function/TypeArguments.kt create mode 100644 idea/testData/refactoring/inline/function/TypeArguments.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt index c1dd63c1e4c..07c3b9b645e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInliner/CodeInliner.kt @@ -217,12 +217,12 @@ class CodeInliner( it[CodeToInline.TYPE_PARAMETER_USAGE_KEY] == parameterName } - val type = resolvedCall.typeArguments[typeParameter]!! + val type = resolvedCall.typeArguments[typeParameter] ?: continue val typeElement = if (explicitTypeArgs != null) { // we use explicit type arguments if available to avoid shortening val explicitArgTypeElement = explicitTypeArgs[index].typeReference?.typeElement ?: continue explicitArgTypeElement.marked(USER_CODE_KEY) } else { - psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)).typeElement!! + psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)).typeElement ?: continue } val typeClassifier = type.constructor.declarationDescriptor diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt b/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt new file mode 100644 index 00000000000..5f75dceabfb --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt @@ -0,0 +1,19 @@ +// "Replace with 'foo(list)'" "true" +// WITH_RUNTIME + +class Builder { + @Deprecated(message = "", level = DeprecationLevel.WARNING, replaceWith = ReplaceWith("foo(list)")) + inline fun addFoo(list: List) { + + } + + inline fun foo(list: List) { + + } + +} + +fun test() { + val b = Builder() + b.addFoo(listOf(1)) +} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt.after new file mode 100644 index 00000000000..e9e3f5033f8 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt.after @@ -0,0 +1,19 @@ +// "Replace with 'foo(list)'" "true" +// WITH_RUNTIME + +class Builder { + @Deprecated(message = "", level = DeprecationLevel.WARNING, replaceWith = ReplaceWith("foo(list)")) + inline fun addFoo(list: List) { + + } + + inline fun foo(list: List) { + + } + +} + +fun test() { + val b = Builder() + b.foo(listOf(1)) +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/TypeArguments.kt b/idea/testData/refactoring/inline/function/TypeArguments.kt new file mode 100644 index 00000000000..28770967ab1 --- /dev/null +++ b/idea/testData/refactoring/inline/function/TypeArguments.kt @@ -0,0 +1,11 @@ +class FunOwner { + fun callMe0() {} + fun callMe1(t: T) {} + fun callMe2(x: X) {} +} + +fun callFun(owner: FunOwner, t: T, x: X) { + owner.callMe0() + owner.callMe1(t) + owner.callMe2(x) +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/TypeArguments.kt.after b/idea/testData/refactoring/inline/function/TypeArguments.kt.after new file mode 100644 index 00000000000..9a00829f790 --- /dev/null +++ b/idea/testData/refactoring/inline/function/TypeArguments.kt.after @@ -0,0 +1,9 @@ +class FunOwner { + fun callMe0() {} + fun callMe1(t: T) {} +} + +fun callFun(owner: FunOwner, t: T, x: X) { + owner.callMe0() + owner.callMe1(t) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 6e0079486cb..2fd67775c45 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -7086,6 +7086,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/keepOriginalIfQualified.kt"); } + @TestMetadata("kt36225.kt") + public void testKt36225() throws Exception { + runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/kt36225.kt"); + } + @TestMetadata("noImplicitTypeArgImportRuntime.kt") public void testNoImplicitTypeArgImportRuntime() throws Exception { runTest("idea/testData/quickfix/deprecatedSymbolUsage/typeArguments/noImplicitTypeArgImportRuntime.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java index 851a491d6b9..a2ffd75faa1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java @@ -95,6 +95,11 @@ public class InlineTestGenerated extends AbstractInlineTest { runTest("idea/testData/refactoring/inline/function/Sequence.kt"); } + @TestMetadata("TypeArguments.kt") + public void testTypeArguments() throws Exception { + runTest("idea/testData/refactoring/inline/function/TypeArguments.kt"); + } + @TestMetadata("UnitReturnType.kt") public void testUnitReturnType() throws Exception { runTest("idea/testData/refactoring/inline/function/UnitReturnType.kt");