Effects: add diagnostic tests on functions from stdlib
========== Introduction of EffectSystem: 18/18
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// !LANGUAGE: +ReturnsEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
fun testCheckSmartcast(x: Any?) {
|
||||
check(x is String)
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun testCheckUnreachableCode() {
|
||||
check(false)
|
||||
// Can't be reported without notion of 'iff'
|
||||
println("Can't get here!")
|
||||
}
|
||||
|
||||
fun testCheckWithMessage(x: Any?) {
|
||||
check(x is String) { "x is not String!" }
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun testCheckWithFailingMessage(x: Any?) {
|
||||
check(x is String) { throw kotlin.IllegalStateException("What a strange idea") }
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun tesCheckNotNullWithMessage(x: Int?) {
|
||||
checkNotNull(x) { "x is null!"}
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.inc()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public fun tesCheckNotNullWithMessage(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||
public fun testCheckSmartcast(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testCheckUnreachableCode(): kotlin.Unit
|
||||
public fun testCheckWithFailingMessage(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testCheckWithMessage(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// !LANGUAGE: +CallsInPlaceEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
fun testRunWithUnitReturn() {
|
||||
val x: Int
|
||||
run { x = 42 }
|
||||
println(x)
|
||||
}
|
||||
|
||||
fun testRunWithReturnValue() {
|
||||
val x: Int
|
||||
val y = run {
|
||||
x = 42
|
||||
"hello"
|
||||
}
|
||||
println(x)
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun testRunWithCoercionToUnit() {
|
||||
val <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!>: Int
|
||||
run {
|
||||
x = 42
|
||||
"hello"
|
||||
}
|
||||
}
|
||||
|
||||
fun testRunWithReceiver(x: Int) {
|
||||
val s: String
|
||||
x.run {
|
||||
s = this.toString()
|
||||
}
|
||||
println(s)
|
||||
}
|
||||
|
||||
fun testWith(x: Int) {
|
||||
val s: String
|
||||
with(x) {
|
||||
s = toString()
|
||||
}
|
||||
println(s)
|
||||
}
|
||||
|
||||
fun testApply(x: Int) {
|
||||
val y: Int
|
||||
val z: Int = x.apply { y = 42 }
|
||||
println(y)
|
||||
println(z)
|
||||
}
|
||||
|
||||
fun testAlso(x: Int) {
|
||||
val y: Int
|
||||
x.also { y = it + 1 }
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun testLet(x: Int) {
|
||||
val z: Int
|
||||
val y: String = x.let {
|
||||
z = 42
|
||||
(it + 1).toString()
|
||||
}
|
||||
println(z)
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun testTakeIf(x: Int?) {
|
||||
val y: Int
|
||||
x.takeIf {
|
||||
y = 42
|
||||
it != null
|
||||
}
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun testTakeUnless(x: Int?) {
|
||||
val y: Int
|
||||
x.takeIf {
|
||||
y = 42
|
||||
it != null
|
||||
}
|
||||
println(y)
|
||||
}
|
||||
|
||||
fun testRepeatOnVal(x: Int) {
|
||||
val y: Int
|
||||
repeat(x) {
|
||||
// reassignment instead of captured val initalization
|
||||
<!VAL_REASSIGNMENT!>y<!> = 42
|
||||
}
|
||||
println(<!UNINITIALIZED_VARIABLE!>y<!>)
|
||||
}
|
||||
|
||||
fun testRepeatOnVar(x: Int) {
|
||||
var y: Int
|
||||
repeat(x) {
|
||||
// no reassignment reported
|
||||
y = 42
|
||||
}
|
||||
// but here we still unsure if 'y' was initialized
|
||||
println(<!UNINITIALIZED_VARIABLE!>y<!>)
|
||||
}
|
||||
|
||||
fun testRepeatOnInitializedVar(x: Int) {
|
||||
var y: Int = 24
|
||||
repeat(x) {
|
||||
y = 42
|
||||
}
|
||||
println(y)
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package
|
||||
|
||||
public fun testAlso(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testApply(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testLet(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testRepeatOnInitializedVar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testRepeatOnVal(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testRepeatOnVar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testRunWithCoercionToUnit(): kotlin.Unit
|
||||
public fun testRunWithReceiver(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun testRunWithReturnValue(): kotlin.Unit
|
||||
public fun testRunWithUnitReturn(): kotlin.Unit
|
||||
public fun testTakeIf(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||
public fun testTakeUnless(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||
public fun testWith(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +ReturnsEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
fun testIsNullOrBlank(x: String?) {
|
||||
if (x.isNullOrBlank()) {
|
||||
x<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
else {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
}
|
||||
|
||||
fun testIsNotNullOrBlank(x: String?) {
|
||||
if (!x.isNullOrBlank()) {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
x<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun testIsNotNullOrBlank(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
public fun testIsNullOrBlank(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +ReturnsEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
fun testIsNullOrEmpty(x: String?) {
|
||||
if (x.isNullOrEmpty()) {
|
||||
x<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
else {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
}
|
||||
|
||||
fun testIsNotNullOrEmpty(x: String?) {
|
||||
if (!x.isNullOrEmpty()) {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
x<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun testIsNotNullOrEmpty(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
public fun testIsNullOrEmpty(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !LANGUAGE: +ReturnsEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
fun testRequireSmartcast(x: Any?) {
|
||||
require(x is String)
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun testRequireUnreachableCode() {
|
||||
require(false)
|
||||
println("Can't get here!")
|
||||
}
|
||||
|
||||
fun testRequireWithMessage(x: Any?) {
|
||||
require(x is String) { "x is not String!" }
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun testRequireWithFailingMessage(x: Any?) {
|
||||
require(x is String) { throw kotlin.IllegalStateException("What a strange idea") }
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
|
||||
fun tesRequireNotNullWithMessage(x: Int?) {
|
||||
requireNotNull(x) { "x is null!"}
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.inc()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public fun tesRequireNotNullWithMessage(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||
public fun testRequireSmartcast(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testRequireUnreachableCode(): kotlin.Unit
|
||||
public fun testRequireWithFailingMessage(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testRequireWithMessage(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
@@ -1031,6 +1031,45 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FromStdlib extends AbstractDiagnosticsTestWithStdLib {
|
||||
public void testAllFilesPresentInFromStdlib() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("check.kt")
|
||||
public void testCheck() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fromStandardKt.kt")
|
||||
public void testFromStandardKt() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isNullOrBlank.kt")
|
||||
public void testIsNullOrBlank() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isNullOrEmpty.kt")
|
||||
public void testIsNullOrEmpty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("require.kt")
|
||||
public void testRequire() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+39
@@ -1031,6 +1031,45 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FromStdlib extends AbstractDiagnosticsTestWithStdLibUsingJavac {
|
||||
public void testAllFilesPresentInFromStdlib() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("check.kt")
|
||||
public void testCheck() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/check.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fromStandardKt.kt")
|
||||
public void testFromStandardKt() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/fromStandardKt.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isNullOrBlank.kt")
|
||||
public void testIsNullOrBlank() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrBlank.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isNullOrEmpty.kt")
|
||||
public void testIsNullOrEmpty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("require.kt")
|
||||
public void testRequire() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/require.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user