[FIR] Add test cases to prove resolution of backlog tickets
^KT-41728 Fixed ^KT-46586 Fixed ^KT-49696 Fixed ^KT-51160 Fixed ^KT-53308 Fixed
This commit is contained in:
+30
@@ -7260,6 +7260,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignmentWithLambda.kt")
|
||||
public void testReassignmentWithLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentWithLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToPropertyInitializer.kt")
|
||||
public void testReferenceToPropertyInitializer() throws Exception {
|
||||
@@ -7544,6 +7550,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
public void testReturnInDeadLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCastAfterDeadCode.kt")
|
||||
public void testSmartCastAfterDeadCode() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/smartCastAfterDeadCode.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -31216,6 +31228,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexSealedContracts.kt")
|
||||
public void testComplexSealedContracts() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexSealedContracts.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||
public void testDataFlowInfoForArguments() throws Exception {
|
||||
@@ -33217,6 +33235,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedInlineModifiedBefore.kt")
|
||||
public void testCapturedInlineModifiedBefore() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileWithBreak.kt")
|
||||
public void testDoWhileWithBreak() throws Exception {
|
||||
@@ -33229,6 +33253,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalityAndIdentity.kt")
|
||||
public void testEqualityAndIdentity() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/equalityAndIdentity.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forEach.kt")
|
||||
public void testForEach() throws Exception {
|
||||
|
||||
+30
@@ -7260,6 +7260,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignmentWithLambda.kt")
|
||||
public void testReassignmentWithLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentWithLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToPropertyInitializer.kt")
|
||||
public void testReferenceToPropertyInitializer() throws Exception {
|
||||
@@ -7544,6 +7550,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
public void testReturnInDeadLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCastAfterDeadCode.kt")
|
||||
public void testSmartCastAfterDeadCode() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/smartCastAfterDeadCode.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -31216,6 +31228,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexSealedContracts.kt")
|
||||
public void testComplexSealedContracts() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexSealedContracts.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||
public void testDataFlowInfoForArguments() throws Exception {
|
||||
@@ -33217,6 +33235,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedInlineModifiedBefore.kt")
|
||||
public void testCapturedInlineModifiedBefore() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileWithBreak.kt")
|
||||
public void testDoWhileWithBreak() throws Exception {
|
||||
@@ -33229,6 +33253,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalityAndIdentity.kt")
|
||||
public void testEqualityAndIdentity() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/equalityAndIdentity.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forEach.kt")
|
||||
public void testForEach() throws Exception {
|
||||
|
||||
+30
@@ -7254,6 +7254,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignmentWithLambda.kt")
|
||||
public void testReassignmentWithLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentWithLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToPropertyInitializer.kt")
|
||||
public void testReferenceToPropertyInitializer() throws Exception {
|
||||
@@ -7538,6 +7544,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
public void testReturnInDeadLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCastAfterDeadCode.kt")
|
||||
public void testSmartCastAfterDeadCode() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/smartCastAfterDeadCode.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -31096,6 +31108,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexSealedContracts.kt")
|
||||
public void testComplexSealedContracts() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexSealedContracts.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||
public void testDataFlowInfoForArguments() throws Exception {
|
||||
@@ -33097,6 +33115,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedInlineModifiedBefore.kt")
|
||||
public void testCapturedInlineModifiedBefore() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileWithBreak.kt")
|
||||
public void testDoWhileWithBreak() throws Exception {
|
||||
@@ -33109,6 +33133,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalityAndIdentity.kt")
|
||||
public void testEqualityAndIdentity() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/equalityAndIdentity.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forEach.kt")
|
||||
public void testForEach() throws Exception {
|
||||
|
||||
+30
@@ -7260,6 +7260,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignmentWithLambda.kt")
|
||||
public void testReassignmentWithLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentWithLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToPropertyInitializer.kt")
|
||||
public void testReferenceToPropertyInitializer() throws Exception {
|
||||
@@ -7544,6 +7550,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
public void testReturnInDeadLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCastAfterDeadCode.kt")
|
||||
public void testSmartCastAfterDeadCode() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/smartCastAfterDeadCode.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -31216,6 +31228,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexSealedContracts.kt")
|
||||
public void testComplexSealedContracts() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexSealedContracts.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||
public void testDataFlowInfoForArguments() throws Exception {
|
||||
@@ -33217,6 +33235,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedInlineModifiedBefore.kt")
|
||||
public void testCapturedInlineModifiedBefore() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileWithBreak.kt")
|
||||
public void testDoWhileWithBreak() throws Exception {
|
||||
@@ -33229,6 +33253,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalityAndIdentity.kt")
|
||||
public void testEqualityAndIdentity() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/equalityAndIdentity.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forEach.kt")
|
||||
public void testForEach() throws Exception {
|
||||
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-41728
|
||||
|
||||
fun foo(a: String?) {
|
||||
if (a == null) {
|
||||
return
|
||||
<!UNREACHABLE_CODE!>"hi".length<!>
|
||||
}
|
||||
a.length
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-41728
|
||||
|
||||
fun foo(a: String?) {
|
||||
if (a == null) {
|
||||
return
|
||||
<!UNREACHABLE_CODE!>"hi".length<!>
|
||||
}
|
||||
a<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-49696
|
||||
|
||||
interface Listener {
|
||||
fun added(item: Any)
|
||||
fun removed(item: Any)
|
||||
}
|
||||
|
||||
val listeners = mutableListOf<Listener>()
|
||||
|
||||
fun smartCast(item: Any?) {
|
||||
var current = item
|
||||
if (current == null) {
|
||||
current = Any()
|
||||
listeners.forEach { it.added(current) }
|
||||
} else {
|
||||
listeners.forEach { it.removed(current) }
|
||||
current = Any()
|
||||
listeners.forEach { it.added(current) }
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-49696
|
||||
|
||||
interface Listener {
|
||||
fun added(item: Any)
|
||||
fun removed(item: Any)
|
||||
}
|
||||
|
||||
val listeners = mutableListOf<Listener>()
|
||||
|
||||
fun smartCast(item: Any?) {
|
||||
var current = item
|
||||
if (current == null) {
|
||||
current = Any()
|
||||
listeners.forEach { it.added(<!SMARTCAST_IMPOSSIBLE!>current<!>) }
|
||||
} else {
|
||||
listeners.forEach { it.removed(<!SMARTCAST_IMPOSSIBLE!>current<!>) }
|
||||
current = Any()
|
||||
listeners.forEach { it.added(<!DEBUG_INFO_SMARTCAST!>current<!>) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-51160
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
sealed interface AsyncStatus<out T : Any> {
|
||||
val value: T?
|
||||
|
||||
data class Pending<out T : Any>(
|
||||
override val value: T? = null,
|
||||
) : AsyncStatus<T>
|
||||
|
||||
sealed interface Terminal<out T : Any> : AsyncStatus<T>
|
||||
|
||||
data class Error<out T : Any>(
|
||||
val error: Throwable,
|
||||
override val value: T? = null,
|
||||
) : Terminal<T>
|
||||
|
||||
data class Success<out T : Any>(
|
||||
override val value: T,
|
||||
) : Terminal<T>
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isPending(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isPending is AsyncStatus.Pending)
|
||||
returns(false) implies (this@isPending is AsyncStatus.Terminal)
|
||||
}
|
||||
return (this is AsyncStatus.Pending)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isSuccess(): Boolean {
|
||||
contract { returns(true) implies (this@isSuccess is AsyncStatus.Success) }
|
||||
return (this is AsyncStatus.Success)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus.Terminal<T>.isSuccess(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isSuccess is AsyncStatus.Success)
|
||||
returns(false) implies (this@isSuccess is AsyncStatus.Error)
|
||||
}
|
||||
return (this is AsyncStatus.Success)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isError(): Boolean {
|
||||
contract { returns(true) implies (this@isError is AsyncStatus.Error) }
|
||||
return (this is AsyncStatus.Error)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus.Terminal<T>.isError(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isError is AsyncStatus.Error)
|
||||
returns(false) implies (this@isError is AsyncStatus.Success)
|
||||
}
|
||||
return (this is AsyncStatus.Error)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isTerminal(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isTerminal is AsyncStatus.Terminal)
|
||||
returns(false) implies (this@isTerminal is AsyncStatus.Pending)
|
||||
}
|
||||
return (this is AsyncStatus.Terminal)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val foo = AsyncStatus.Pending<String>()
|
||||
if (!foo.isPending()) {
|
||||
if (foo.isSuccess()) {
|
||||
nonNullPrint(foo.value)
|
||||
}
|
||||
if (foo.isError()) {
|
||||
foo.error.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun nonNullPrint(printMe: String) {
|
||||
println(printMe)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-51160
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
sealed interface AsyncStatus<out T : Any> {
|
||||
val value: T?
|
||||
|
||||
data class Pending<out T : Any>(
|
||||
override val value: T? = null,
|
||||
) : AsyncStatus<T>
|
||||
|
||||
sealed interface Terminal<out T : Any> : AsyncStatus<T>
|
||||
|
||||
data class Error<out T : Any>(
|
||||
val error: Throwable,
|
||||
override val value: T? = null,
|
||||
) : Terminal<T>
|
||||
|
||||
data class Success<out T : Any>(
|
||||
override val value: T,
|
||||
) : Terminal<T>
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isPending(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isPending is AsyncStatus.Pending)
|
||||
returns(false) implies (this@isPending is AsyncStatus.Terminal)
|
||||
}
|
||||
return (this is AsyncStatus.Pending)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isSuccess(): Boolean {
|
||||
contract { returns(true) implies (this@isSuccess is AsyncStatus.Success) }
|
||||
return (this is AsyncStatus.Success)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus.Terminal<T>.isSuccess(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isSuccess is AsyncStatus.Success)
|
||||
returns(false) implies (this@isSuccess is AsyncStatus.Error)
|
||||
}
|
||||
return (this is AsyncStatus.Success)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isError(): Boolean {
|
||||
contract { returns(true) implies (this@isError is AsyncStatus.Error) }
|
||||
return (this is AsyncStatus.Error)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus.Terminal<T>.isError(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isError is AsyncStatus.Error)
|
||||
returns(false) implies (this@isError is AsyncStatus.Success)
|
||||
}
|
||||
return (this is AsyncStatus.Error)
|
||||
}
|
||||
|
||||
fun <T : Any> AsyncStatus<T>.isTerminal(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isTerminal is AsyncStatus.Terminal)
|
||||
returns(false) implies (this@isTerminal is AsyncStatus.Pending)
|
||||
}
|
||||
return (this is AsyncStatus.Terminal)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val foo = AsyncStatus.Pending<String>()
|
||||
if (!foo.isPending()) {
|
||||
if (<!DEBUG_INFO_SMARTCAST!>foo<!>.isSuccess()) {
|
||||
nonNullPrint(<!TYPE_MISMATCH!>foo.value<!>)
|
||||
}
|
||||
if (<!DEBUG_INFO_SMARTCAST!>foo<!>.isError()) {
|
||||
foo.<!UNRESOLVED_REFERENCE!>error<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>printStackTrace<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun nonNullPrint(printMe: String) {
|
||||
println(printMe)
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-46586
|
||||
|
||||
inline fun run(block: () -> Unit) = block()
|
||||
|
||||
fun test() {
|
||||
var label: String? = null
|
||||
run {
|
||||
label = "zzz"
|
||||
}
|
||||
if (label == null) {
|
||||
label = "zzz"
|
||||
}
|
||||
label.isBlank()
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-46586
|
||||
|
||||
inline fun run(block: () -> Unit) = block()
|
||||
|
||||
fun test() {
|
||||
var label: String? = null
|
||||
run {
|
||||
label = "zzz"
|
||||
}
|
||||
if (label == null) {
|
||||
label = "zzz"
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>label<!>.isBlank()
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-53308
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun <E> checkEquality(arg: E?) { contract { returns() implies (arg != null) } }
|
||||
fun <E> checkIdentity(arg: E?) { contract { <!ERROR_IN_CONTRACT_DESCRIPTION("NOT_IDENTITY operator call is illegal in contract description")!>returns() implies (arg !== null)<!> } }
|
||||
fun checkTrue(statement: Boolean) { contract { returns() implies statement } }
|
||||
fun checkFalse(statement: Boolean) { contract { returns() implies !statement } }
|
||||
|
||||
fun consume(arg: String) {}
|
||||
|
||||
fun test(a: String?) {
|
||||
a.let {
|
||||
checkEquality(it)
|
||||
consume(it)
|
||||
}
|
||||
a.let {
|
||||
checkIdentity(it)
|
||||
consume(<!ARGUMENT_TYPE_MISMATCH!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkTrue(it != null)
|
||||
consume(it)
|
||||
}
|
||||
a.let {
|
||||
checkTrue(it !== null)
|
||||
consume(it)
|
||||
}
|
||||
a.let {
|
||||
checkFalse(it == null)
|
||||
consume(it)
|
||||
}
|
||||
a.let {
|
||||
checkFalse(it === null)
|
||||
consume(it)
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-53308
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun <E> checkEquality(arg: E?) { contract { returns() implies (arg != null) } }
|
||||
fun <E> checkIdentity(arg: E?) { contract { returns() implies (arg !== null) } }
|
||||
fun checkTrue(statement: Boolean) { contract { returns() implies statement } }
|
||||
fun checkFalse(statement: Boolean) { contract { returns() implies !statement } }
|
||||
|
||||
fun consume(arg: String) {}
|
||||
|
||||
fun test(a: String?) {
|
||||
a.let {
|
||||
checkEquality(it)
|
||||
consume(<!DEBUG_INFO_SMARTCAST!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkIdentity(it)
|
||||
consume(<!DEBUG_INFO_SMARTCAST!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkTrue(it != null)
|
||||
consume(<!DEBUG_INFO_SMARTCAST!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkTrue(it !== null)
|
||||
consume(<!TYPE_MISMATCH!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkFalse(it == null)
|
||||
consume(<!DEBUG_INFO_SMARTCAST!>it<!>)
|
||||
}
|
||||
a.let {
|
||||
checkFalse(it === null)
|
||||
consume(<!TYPE_MISMATCH!>it<!>)
|
||||
}
|
||||
}
|
||||
Generated
+30
@@ -7260,6 +7260,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentInTryCatchWithJumps.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignmentWithLambda.kt")
|
||||
public void testReassignmentWithLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/reassignmentWithLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToPropertyInitializer.kt")
|
||||
public void testReferenceToPropertyInitializer() throws Exception {
|
||||
@@ -7544,6 +7550,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
public void testReturnInDeadLambda() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/returnInDeadLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCastAfterDeadCode.kt")
|
||||
public void testSmartCastAfterDeadCode() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/smartCastAfterDeadCode.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -33204,6 +33216,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexConditionsWithExcl.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexSealedContracts.kt")
|
||||
public void testComplexSealedContracts() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/complexSealedContracts.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||
public void testDataFlowInfoForArguments() throws Exception {
|
||||
@@ -35205,6 +35223,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("capturedInlineModifiedBefore.kt")
|
||||
public void testCapturedInlineModifiedBefore() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInlineModifiedBefore.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doWhileWithBreak.kt")
|
||||
public void testDoWhileWithBreak() throws Exception {
|
||||
@@ -35217,6 +35241,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalityAndIdentity.kt")
|
||||
public void testEqualityAndIdentity() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/varnotnull/equalityAndIdentity.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forEach.kt")
|
||||
public void testForEach() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user