From fe233de825aa2e47135b428395c3432dc2e82c4b Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 16 Oct 2018 15:50:26 +0300 Subject: [PATCH] Report error for `Result` as an extension receiver with safe call #KT-27620 Fixed --- .../calls/checkers/ResultTypeWithNullableOperatorsChecker.kt | 3 ++- .../coroutines/usageOfResultTypeWithNullableOperators.kt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ResultTypeWithNullableOperatorsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ResultTypeWithNullableOperatorsChecker.kt index 3fac3b10d5c..1f218983370 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ResultTypeWithNullableOperatorsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/ResultTypeWithNullableOperatorsChecker.kt @@ -21,7 +21,8 @@ class ResultTypeWithNullableOperatorsChecker : CallChecker { when { operationNode?.elementType == KtTokens.SAFE_ACCESS -> { - val receiver = resolvedCall.resultingDescriptor.dispatchReceiverParameter ?: return + val resultingDescriptor = resolvedCall.resultingDescriptor + val receiver = resultingDescriptor.extensionReceiverParameter ?: resultingDescriptor.dispatchReceiverParameter ?: return if (receiver.type.isResultType()) { context.trace.report(Errors.RESULT_CLASS_WITH_NULLABLE_OPERATOR.on(operationNode!!.psi, "?.")) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.kt index bbd5a0b0639..2528c9c30db 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/usageOfResultTypeWithNullableOperators.kt @@ -22,6 +22,7 @@ fun nullableOperators(r1: Result?, b: Boolean) { if (b) { r1?.toString() + r1?.let { } returnInt()?.intResult?.toString() asFun()?.toString() id(r1)?.toString()