Move changes from dfb379d under new language feature (#KT-28672)

Changes from that commit are breaking, and should be pass throw LC
This commit is contained in:
Dmitriy Novozhilov
2019-02-04 16:19:58 +03:00
parent cf25cab773
commit 9129210cfe
8 changed files with 68 additions and 4 deletions
@@ -132,7 +132,7 @@ class EffectSystem(
}
private fun getNonTrivialComputation(expression: KtExpression, trace: BindingTrace, moduleDescriptor: ModuleDescriptor): Computation? {
val visitor = EffectsExtractingVisitor(trace, moduleDescriptor, dataFlowValueFactory, constants)
val visitor = EffectsExtractingVisitor(trace, moduleDescriptor, dataFlowValueFactory, constants, languageVersionSettings)
return visitor.extractOrGetCached(expression).takeUnless { it == UNKNOWN_COMPUTATION }
}
}
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.contracts
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.contracts.description.ContractProviderKey
import org.jetbrains.kotlin.contracts.model.Computation
import org.jetbrains.kotlin.contracts.model.ConditionalEffect
@@ -56,7 +58,8 @@ class EffectsExtractingVisitor(
private val trace: BindingTrace,
private val moduleDescriptor: ModuleDescriptor,
private val dataFlowValueFactory: DataFlowValueFactory,
private val constants: ESConstants
private val constants: ESConstants,
private val languageVersionSettings: LanguageVersionSettings
) : KtVisitor<Computation, Unit>() {
private val builtIns: KotlinBuiltIns get() = moduleDescriptor.builtIns
@@ -162,7 +165,13 @@ class EffectsExtractingVisitor(
private fun ReceiverValue.toComputation(): Computation = when (this) {
is ExpressionReceiver -> extractOrGetCached(expression)
is ExtensionReceiver -> ESReceiverWithDataFlowValue(this, createDataFlowValue())
is ExtensionReceiver -> {
if (languageVersionSettings.supportsFeature(LanguageFeature.ContractsOnCallsWithImplicitReceiver)) {
ESReceiverWithDataFlowValue(this, createDataFlowValue())
} else {
UNKNOWN_COMPUTATION
}
}
else -> UNKNOWN_COMPUTATION
}
@@ -20,7 +20,7 @@ fun smartcastOnReceiver(s: String?) {
<!UNSAFE_CALL!>length<!>
}
else {
<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>length<!>
<!UNSAFE_CALL!>length<!>
}
}
}
@@ -0,0 +1,38 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +ContractsOnCallsWithImplicitReceiver
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
//
// ISSUE: KT-28672
import kotlin.contracts.*
fun CharSequence?.isNullOrEmpty(): Boolean {
contract {
returns(false) implies (this@isNullOrEmpty != null)
}
return this == null || <!DEBUG_INFO_SMARTCAST!>this<!>.length == 0
}
fun smartcastOnReceiver(s: String?) {
with(s) {
if (isNullOrEmpty()) {
<!UNSAFE_CALL!>length<!>
}
else {
<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>length<!>
}
}
}
fun mixedReceiver(s: String?) {
if (!s.isNullOrEmpty()) {
with(<!DEBUG_INFO_SMARTCAST!>s<!>) {
length
}
} else {
with(s) {
<!UNSAFE_CALL!>length<!>
}
}
}
@@ -0,0 +1,6 @@
package
public fun mixedReceiver(/*0*/ s: kotlin.String?): kotlin.Unit
public fun smartcastOnReceiver(/*0*/ s: kotlin.String?): kotlin.Unit
public fun kotlin.CharSequence?.isNullOrEmpty(): kotlin.Boolean
Returns(FALSE) -> <this> != null
@@ -1301,6 +1301,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt");
}
@TestMetadata("extensionReceiver_after.kt")
public void testExtensionReceiver_after() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.kt");
}
@TestMetadata("intersectingInfo.kt")
public void testIntersectingInfo() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.kt");
@@ -1301,6 +1301,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt");
}
@TestMetadata("extensionReceiver_after.kt")
public void testExtensionReceiver_after() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver_after.kt");
}
@TestMetadata("intersectingInfo.kt")
public void testIntersectingInfo() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.kt");
@@ -121,6 +121,7 @@ enum class LanguageFeature(
InlineClasses(sinceVersion = KOTLIN_1_3, defaultState = State.ENABLED_WITH_WARNING, kind = UNSTABLE_FEATURE),
ContractsOnCallsWithImplicitReceiver(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED),
;
val presentableName: String