Add test on safecall of function with returns(null) contract
Currently with non-desired testdata, fix incoming in the next commit.
This commit is contained in:
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||||
|
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
fun Any.nullWhenString(): Any? {
|
||||||
|
contract {
|
||||||
|
returns(null) implies (this@nullWhenString is String)
|
||||||
|
}
|
||||||
|
return if (this is String) null else this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(x: Int?) {
|
||||||
|
if (x?.nullWhenString() == null) {
|
||||||
|
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(/*0*/ x: kotlin.Int?): kotlin.Unit
|
||||||
|
public fun kotlin.Any.nullWhenString(): kotlin.Any?
|
||||||
|
Returns(NULL) -> <this> is String
|
||||||
+5
@@ -1286,6 +1286,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("safecallAndReturnsNull.kt")
|
||||||
|
public void testSafecallAndReturnsNull() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("throwsEffect.kt")
|
@TestMetadata("throwsEffect.kt")
|
||||||
public void testThrowsEffect() throws Exception {
|
public void testThrowsEffect() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.kt");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -1286,6 +1286,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("safecallAndReturnsNull.kt")
|
||||||
|
public void testSafecallAndReturnsNull() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/safecallAndReturnsNull.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("throwsEffect.kt")
|
@TestMetadata("throwsEffect.kt")
|
||||||
public void testThrowsEffect() throws Exception {
|
public void testThrowsEffect() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/throwsEffect.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user