[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:
+10
@@ -1092,6 +1092,16 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/contracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("contractFromOtherModule.kt")
|
||||
public void testContractFromOtherModule() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("contractFromOtherModule_samePackage.kt")
|
||||
public void testContractFromOtherModule_samePackage() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule_samePackage.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericContract.kt")
|
||||
public void testGenericContract() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/genericContract.kt");
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
Module: lib
|
||||
FILE: module_lib_contractFromOtherModule.kt
|
||||
package lib
|
||||
|
||||
public final fun requireIsTrue(value: R|kotlin/Boolean|): R|kotlin/Unit|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(WILDCARD) -> value
|
||||
>
|
||||
{
|
||||
when () {
|
||||
R|<local>/value|.R|kotlin/Boolean.not|() -> {
|
||||
throw R|java/lang/IllegalArgumentException.IllegalArgumentException|()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Module: main
|
||||
FILE: module_main_contractFromOtherModule.kt
|
||||
package main
|
||||
|
||||
public final fun test(s: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
R|lib/requireIsTrue|((R|<local>/s| is R|kotlin/String|))
|
||||
R|<local>/s|.R|kotlin/String.length|
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// SKIP_JAVAC
|
||||
// This directive is needed to skip this test in LazyBodyIsNotTouchedTilContractsPhaseTestGenerated,
|
||||
// because it fails to parse module structure of multimodule test
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
// MODULE: lib
|
||||
package lib
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun requireIsTrue(value: Boolean) contract [
|
||||
returns() implies value
|
||||
] {
|
||||
if (!value) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
package main
|
||||
|
||||
import lib.requireIsTrue
|
||||
|
||||
fun test(s: Any) {
|
||||
requireIsTrue(s is String)
|
||||
s.length
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
Module: lib
|
||||
FILE: module_lib_contractFromOtherModule_samePackage.kt
|
||||
package main
|
||||
|
||||
public final fun requireIsTrue(value: R|kotlin/Boolean|): R|kotlin/Unit|
|
||||
[R|Contract description]
|
||||
<
|
||||
Returns(WILDCARD) -> value
|
||||
>
|
||||
{
|
||||
when () {
|
||||
R|<local>/value|.R|kotlin/Boolean.not|() -> {
|
||||
throw R|java/lang/IllegalArgumentException.IllegalArgumentException|()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Module: main
|
||||
FILE: module_main_contractFromOtherModule_samePackage.kt
|
||||
package main
|
||||
|
||||
public final fun test(s: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
R|main/requireIsTrue|((R|<local>/s| is R|kotlin/String|))
|
||||
R|<local>/s|.R|kotlin/String.length|
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// SKIP_JAVAC
|
||||
// This directive is needed to skip this test in LazyBodyIsNotTouchedTilContractsPhaseTestGenerated,
|
||||
// because it fails to parse module structure of multimodule test
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
// MODULE: lib
|
||||
package main
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun requireIsTrue(value: Boolean) contract [
|
||||
returns() implies value
|
||||
] {
|
||||
if (!value) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
package main
|
||||
|
||||
fun test(s: Any) {
|
||||
requireIsTrue(s is String)
|
||||
s.length
|
||||
}
|
||||
+12
@@ -1257,6 +1257,18 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/contracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contractFromOtherModule.kt")
|
||||
public void testContractFromOtherModule() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contractFromOtherModule_samePackage.kt")
|
||||
public void testContractFromOtherModule_samePackage() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule_samePackage.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericContract.kt")
|
||||
public void testGenericContract() throws Exception {
|
||||
|
||||
+12
@@ -1257,6 +1257,18 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/contracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contractFromOtherModule.kt")
|
||||
public void testContractFromOtherModule() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contractFromOtherModule_samePackage.kt")
|
||||
public void testContractFromOtherModule_samePackage() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/contracts/contractFromOtherModule_samePackage.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericContract.kt")
|
||||
public void testGenericContract() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user