[FIR IDE] Ensure resolve to CONTRACTS phase in ReturnTypeCalculator
If we want to analyse some function's call, we need to know about its contracts, otherwise resolving the following code would be broken. Computing return type of function is a prerequisite to using it in any sensible way, so it's the best place to resolve it to CONTRACTS KT-50733
This commit is contained in:
+17
-1
@@ -1,4 +1,3 @@
|
||||
// FIR_IDE_IGNORE
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
|
||||
import kotlin.contracts.*
|
||||
@@ -16,6 +15,15 @@ fun case_2_1(x: Number?) {
|
||||
println(x.toByte())
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class Child : Base() {
|
||||
fun case_3_1(x: Any?) {
|
||||
if (case_3_2(x)) {
|
||||
x.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case_1_2(x: Any?): Boolean {
|
||||
contract { returns(true) implies (x is String) }
|
||||
@@ -27,3 +35,11 @@ fun case_2_2(x: Any?) {
|
||||
contract { returns() implies(x != null) }
|
||||
if (x == null) throw Exception()
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
open class Base {
|
||||
fun case_3_2(x: Any?): Boolean {
|
||||
contract { returns(true) implies (x is String) }
|
||||
return x is String
|
||||
}
|
||||
}
|
||||
Vendored
+16
-2
@@ -1,5 +1,4 @@
|
||||
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||
// FIR_IDE_IGNORE
|
||||
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE)
|
||||
@@ -24,6 +23,15 @@ fun case_2_1(x: Number?) {
|
||||
println(<!DEBUG_INFO_SMARTCAST!>x<!>.toByte())
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class Child : Base() {
|
||||
fun case_3_1(x: Any?) {
|
||||
if (case_3_2(x)) {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case_1_2(x: Any?): Boolean {
|
||||
contract { returns(true) implies (x is String) }
|
||||
@@ -36,4 +44,10 @@ fun case_2_2(x: Any?) {
|
||||
if (x == null) throw Exception()
|
||||
}
|
||||
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
open class Base {
|
||||
fun case_3_2(x: Any?): Boolean {
|
||||
contract { returns(true) implies (x is String) }
|
||||
return x is String
|
||||
}
|
||||
}
|
||||
compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/pos/1.txt
Vendored
+20
@@ -8,3 +8,23 @@ public fun case_2_1(/*0*/ x: kotlin.Number?): kotlin.Unit
|
||||
public fun case_2_2(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
Returns(WILDCARD) -> x != null
|
||||
|
||||
public open class Base {
|
||||
public constructor Base()
|
||||
public final fun case_3_2(/*0*/ x: kotlin.Any?): kotlin.Boolean
|
||||
Returns(TRUE) -> x is String
|
||||
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Child : Base {
|
||||
public constructor Child()
|
||||
public final fun case_3_1(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun case_3_2(/*0*/ x: kotlin.Any?): kotlin.Boolean
|
||||
Returns(TRUE) -> x is String
|
||||
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user