From c0c9552f4cdcb271c4b6233376356c8264b2d283 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 14 Oct 2014 21:06:51 +0400 Subject: [PATCH] KT-5971 Missing error when fun argument is safe call #KT-5971 Fixed --- .../jetbrains/jet/lang/resolve/calls/CallCompleter.kt | 7 ++++--- .../tests/resolve/nestedCalls/kt5971NestedSafeCall.kt | 9 +++++++++ .../tests/resolve/nestedCalls/kt5971NestedSafeCall.txt | 4 ++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 6 ++++++ j2k/src/org/jetbrains/jet/j2k/Converter.kt | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt index da8f67e4232..f4e73c82924 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt @@ -246,7 +246,7 @@ public class CallCompleter( updatedType = ArgumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context as ResolutionContext<*>, expression) } - updateRecordedTypeForArgument(updatedType, recordedType, expression, context.trace) + updatedType = updateRecordedTypeForArgument(updatedType, recordedType, expression, context.trace) // While the expected type is not known, the function literal arguments are not analyzed (to analyze function literal bodies once), // but they should be analyzed when the expected type is known (during the call completion). @@ -294,8 +294,8 @@ public class CallCompleter( recordedType: JetType?, argumentExpression: JetExpression, trace: BindingTrace - ) { - if (recordedType == updatedType) return + ): JetType? { + if (recordedType == updatedType || updatedType == null) return updatedType fun deparenthesizeOrGetSelector(expression: JetExpression?): JetExpression? { val deparenthesized = JetPsiUtil.deparenthesizeOnce(expression, /* deparenthesizeBinaryExpressionWithTypeRHS = */ false) @@ -315,6 +315,7 @@ public class CallCompleter( BindingContextUtils.updateRecordedType( updatedType, expression, trace, /* shouldBeMadeNullable = */ hasNecessarySafeCall(expression, trace)) } + return trace[BindingContext.EXPRESSION_TYPE, argumentExpression] } private fun hasNecessarySafeCall(expression: JetExpression, trace: BindingTrace): Boolean { diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.kt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.kt new file mode 100644 index 00000000000..23bb5f3362d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +//KT-5971 Missing error when fun argument is safe call + +fun foo(i: Int) {} + +fun test(s: String?) { + foo(s?.length) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.txt b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.txt new file mode 100644 index 00000000000..a97626d358d --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.txt @@ -0,0 +1,4 @@ +package + +internal fun foo(/*0*/ i: kotlin.Int): kotlin.Unit +internal fun test(/*0*/ s: kotlin.String?): kotlin.Unit \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index b86fdfc57ab..05f0f57aa84 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -8967,6 +8967,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt5971NestedSafeCall.kt") + public void testKt5971NestedSafeCall() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/nestedCalls/kt5971NestedSafeCall.kt"); + doTest(fileName); + } + } @TestMetadata("compiler/testData/diagnostics/tests/resolve/specialConstructions") diff --git a/j2k/src/org/jetbrains/jet/j2k/Converter.kt b/j2k/src/org/jetbrains/jet/j2k/Converter.kt index f6b4899497a..2f3a9c138eb 100644 --- a/j2k/src/org/jetbrains/jet/j2k/Converter.kt +++ b/j2k/src/org/jetbrains/jet/j2k/Converter.kt @@ -279,7 +279,7 @@ public class Converter private(val project: Project, annotations, modifiers, typeConverter.convertType(field.getType(), Nullability.NotNull), - ExpressionList(convertExpressions(argumentList?.getExpressions())).assignPrototype(argumentList)) + ExpressionList(convertExpressions(argumentList?.getExpressions() ?: array())).assignPrototype(argumentList)) } else { val isVal = isVal(referenceSearcher, field)