Fix inheritance in stdlib contracts code (KT-26409)

This commit is contained in:
victor.petukhov
2018-09-11 14:19:10 +03:00
parent cba99a1e67
commit 50d9dbbfc1
9 changed files with 50 additions and 49 deletions
@@ -0,0 +1,20 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_EXPRESSION
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE)
SECTION: contracts
CATEGORY: declarations, contractBuilder, common
NUMBER: 13
DESCRIPTION: Contract function with CallsInPlace effect with not allowed implies.
ISSUES: KT-26409
*/
import kotlin.contracts.*
fun case_1(value_1: Any?, block: () -> Unit) {
<!ERROR_IN_CONTRACT_DESCRIPTION!>contract<!> { callsInPlace(block, InvocationKind.EXACTLY_ONCE) <!UNRESOLVED_REFERENCE!>implies<!> (value_1 != null) }
if (value_1 != null) block()
}
@@ -0,0 +1,3 @@
package
public fun case_1(/*0*/ value_1: kotlin.Any?, /*1*/ block: () -> kotlin.Unit): kotlin.Unit
@@ -8,14 +8,19 @@
SECTION: contracts
CATEGORY: declarations, contractBuilder, common
NUMBER: 5
DESCRIPTION: Contract function with CallsInPlace effect with not allowed implies.
DESCRIPTION: contracts with not allowed conditions with boolean constants or constant expressions in implies.
UNEXPECTED BEHAVIOUR
ISSUES: KT-26409
ISSUES: KT-26491
*/
import kotlin.contracts.*
fun case_1(value_1: Any?, block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) implies (value_1 != null) }
if (value_1 != null) block()
fun case_1(): Boolean {
contract { returns(true) implies true }
return true
}
fun case_2(): Boolean {
contract { returns(true) implies (true || false) }
return true || false
}
@@ -1,4 +1,7 @@
package
public fun case_1(/*0*/ value_1: kotlin.Any?, /*1*/ block: () -> kotlin.Unit): kotlin.Unit
CallsInPlace(block, EXACTLY_ONCE) -> value_1 != null
public fun case_1(): kotlin.Boolean
Returns(TRUE) -> TRUE
public fun case_2(): kotlin.Boolean
Returns(TRUE) -> TRUE || FALSE
@@ -1,26 +0,0 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_EXPRESSION
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
/*
KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
SECTION: contracts
CATEGORY: declarations, contractBuilder, common
NUMBER: 6
DESCRIPTION: contracts with not allowed conditions with boolean constants or constant expressions in implies.
UNEXPECTED BEHAVIOUR
ISSUES: KT-26491
*/
import kotlin.contracts.*
fun case_1(): Boolean {
contract { returns(true) implies true }
return true
}
fun case_2(): Boolean {
contract { returns(true) implies (true || false) }
return true || false
}
@@ -1,7 +0,0 @@
package
public fun case_1(): kotlin.Boolean
Returns(TRUE) -> TRUE
public fun case_2(): kotlin.Boolean
Returns(TRUE) -> TRUE || FALSE
@@ -1085,6 +1085,11 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/12.kt");
}
@TestMetadata("13.kt")
public void test13() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/13.kt");
}
@TestMetadata("2.kt")
public void test2() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/neg/2.kt");
@@ -1163,11 +1168,6 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/pos/5.kt");
}
@TestMetadata("6.kt")
public void test6() throws Exception {
runTest("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/pos/6.kt");
}
public void testAllFilesPresentInPos() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractBuilder/common/pos"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@@ -7,6 +7,9 @@ package kotlin.contracts
import kotlin.internal.ContractsDsl
/**
* Abstract effect, the inheritors of which are used in [ContractBuilder] to describe the contract function.
*/
@ContractsDsl
@ExperimentalContracts
@SinceKotlin("1.3")
@@ -29,7 +32,7 @@ public interface ConditionalEffect : Effect
@ContractsDsl
@ExperimentalContracts
@SinceKotlin("1.3")
public interface SimpleEffect {
public interface SimpleEffect : Effect {
/**
* The function to specify an additional condition for some `SimpleEffect`.
*
@@ -71,4 +74,4 @@ public interface ReturnsNotNull : SimpleEffect
@ContractsDsl
@ExperimentalContracts
@SinceKotlin("1.3")
public interface CallsInPlace : SimpleEffect
public interface CallsInPlace : Effect
@@ -2570,7 +2570,7 @@ public final class kotlin/concurrent/TimersKt {
public static final fun timer (Ljava/lang/String;Z)Ljava/util/Timer;
}
public abstract interface class kotlin/contracts/CallsInPlace : kotlin/contracts/SimpleEffect {
public abstract interface class kotlin/contracts/CallsInPlace : kotlin/contracts/Effect {
}
public abstract interface class kotlin/contracts/ConditionalEffect : kotlin/contracts/Effect {
@@ -2608,7 +2608,7 @@ public abstract interface class kotlin/contracts/Returns : kotlin/contracts/Simp
public abstract interface class kotlin/contracts/ReturnsNotNull : kotlin/contracts/SimpleEffect {
}
public abstract interface class kotlin/contracts/SimpleEffect {
public abstract interface class kotlin/contracts/SimpleEffect : kotlin/contracts/Effect {
public abstract fun implies (Z)Lkotlin/contracts/ConditionalEffect;
}