From 70a1beeff648be10989fec7663c8d022b9cd82bf Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Wed, 22 Nov 2017 21:43:23 +0300 Subject: [PATCH] [NI] Use ErrorType in ParseErrorKotlinCallArgument Previously, there was receiver of type Nothing, which could case result of the call to be inferred to Nothing too. This could case bogus UNREACHABLE_CODE diagnostics in cases like this: ``` fun id(x: T) = x fun test() { id(unresolvedReference) // type of statement is 'Nothing' // ... everything here is marked as unreachable ... } ``` This commit changes type of receiver for such calls form Nothing to ErrorType. --- .../kotlin/resolve/calls/tower/NewCallArguments.kt | 7 ++++++- .../tests/inference/nestedCalls/binaryExpressions.kt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt index 704ab001f62..75c54be9a1d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.prepareReceiverRegardingCaptureTypes +import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo @@ -71,7 +72,11 @@ class ParseErrorKotlinCallArgument( override val dataFlowInfoAfterThisArgument: DataFlowInfo, builtIns: KotlinBuiltIns ): ExpressionKotlinCallArgument, SimplePSIKotlinCallArgument() { - override val receiver = ReceiverValueWithSmartCastInfo(TransientReceiver(builtIns.nothingType), emptySet(), isStable = true) + override val receiver = ReceiverValueWithSmartCastInfo( + TransientReceiver(ErrorUtils.createErrorType("Error type for ParseError-argument $valueArgument")), + possibleTypes = emptySet(), + isStable = true + ) override val isSafeCall: Boolean get() = false diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt index 1d553689322..7dfa9c04a2c 100644 --- a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt @@ -57,7 +57,7 @@ fun test3(z: Z) { //'in' operation fun test4(collection: Collection>) { id(newA() in collection) - id(newA() in collection) + id(newA() in collection) } //boolean operations