[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/operatorsTests/andOperator.fir.kt
Vendored
+81
@@ -0,0 +1,81 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun trueWhenInt(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is Int)
|
||||
}
|
||||
return x is Int
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
fun falseWhenInt(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is Int)
|
||||
}
|
||||
return x !is Int
|
||||
}
|
||||
|
||||
|
||||
// ==== Actual tests ====
|
||||
|
||||
fun truetrue(x: Any?) {
|
||||
if (trueWhenString(x) && trueWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
|
||||
fun truefalse(x: Any?) {
|
||||
if (trueWhenString(x) && falseWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun falsetrue(x: Any?) {
|
||||
if (falseWhenString(x) && trueWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun falsefalse(x: Any?) {
|
||||
if (falseWhenString(x) && falseWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
// Note that we can't argue that we have any of smartcasts here,
|
||||
// because we don't know which one of both arguments was 'false' to bring us here
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun annotatedTrueAndTrue(x: Any?) {
|
||||
if (trueWhenString(x) && true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedTrueAndFalse(x: Any?) {
|
||||
if (trueWhenString(x) && false) {
|
||||
// Unreachable
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseAndTrue(x: Any?) {
|
||||
if (falseWhenString(x) && true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseAndFalse(x: Any?) {
|
||||
if (falseWhenString(x) && false) {
|
||||
// Unreachable
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
fun unknownFunction(x: Any?) = x == 42
|
||||
|
||||
|
||||
|
||||
|
||||
fun annotatedTrue(x: Any?) {
|
||||
if (trueWhenString(x) && unknownFunction(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalse(x: Any?) {
|
||||
if (falseWhenString(x) && unknownFunction(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedTrueWithVariable(x: Any?, b: Boolean) {
|
||||
if (trueWhenString(x) && b) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseWithVariable(x: Any?, b: Boolean) {
|
||||
if (falseWhenString(x) && b) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun myEqualsNull(x: Int?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x != null)
|
||||
}
|
||||
return x == null
|
||||
}
|
||||
|
||||
fun myEqualsNotNull(x: Int?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x != null)
|
||||
}
|
||||
return x != null
|
||||
}
|
||||
|
||||
fun testBasicEquals(x: Int?) {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
|
||||
if (myEqualsNull(x)) {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
|
||||
fun testBasicNotEquals(x: Int?) {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
|
||||
if (myEqualsNotNull(x)) {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun safeIsString(x: Any?): Boolean? {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x?.let { it is String }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun equalsTrue(x: Any?) {
|
||||
if (safeIsString(x) == true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun equalsFalse(x: Any?) {
|
||||
if (safeIsString(x) == false) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun equalsNull(x: Any?) {
|
||||
if (safeIsString(x) == null) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun notEqualsTrue(x: Any?) {
|
||||
if (safeIsString(x) != true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun notEqualsFalse(x: Any?) {
|
||||
if (safeIsString(x) != false) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun notEqualsNull(x: Any?) {
|
||||
if (safeIsString(x) != null) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun isString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
|
||||
fun notIsString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun testSimple(x: Any?) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
if (isString(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testSpilling(x: Any?) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
if (isString(x)) x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun testInversion(x: Any?) {
|
||||
if (notIsString(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testInversionSpilling(x: Any?) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
if (notIsString(x)) else x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun trueWhenInt(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is Int)
|
||||
}
|
||||
return x is Int
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
fun falseWhenInt(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is Int)
|
||||
}
|
||||
return x !is Int
|
||||
}
|
||||
|
||||
fun truetrue(x: Any?) {
|
||||
if (trueWhenString(x) || trueWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun truefalse(x: Any?) {
|
||||
if (trueWhenString(x) || falseWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun falsetrue(x: Any?) {
|
||||
if (falseWhenString(x) || trueWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun falsefalse(x: Any?) {
|
||||
if (falseWhenString(x) || falseWhenInt(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
x.<!AMBIGUITY!>inc<!>()
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
fun annotatedTrueOrTrue(x: Any?) {
|
||||
if (trueWhenString(x) || true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
// Unreachable
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedTrueOrFalse(x: Any?) {
|
||||
if (trueWhenString(x) || false) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseOrTrue(x: Any?) {
|
||||
if (falseWhenString(x) || true) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
// Unreachable
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseOrFalse(x: Any?) {
|
||||
if (falseWhenString(x) || false) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun trueWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
fun falseWhenString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x is String)
|
||||
}
|
||||
return x !is String
|
||||
}
|
||||
|
||||
fun unknownFunction(x: Any?) = x == 42
|
||||
|
||||
|
||||
|
||||
|
||||
fun annotatedTrue(x: Any?) {
|
||||
if (trueWhenString(x) || unknownFunction(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalse(x: Any?) {
|
||||
if (falseWhenString(x) || unknownFunction(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedTrueWithVariable(x: Any?, b: Boolean) {
|
||||
if (trueWhenString(x) || b) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun annotatedFalseWithVariable(x: Any?, b: Boolean) {
|
||||
if (falseWhenString(x) || b) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
else {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user