K2 Scripting: add missing contracts resolving in scripts
#KT-64074 fixed
This commit is contained in:
committed by
Space Team
parent
3b70b3d92d
commit
a5c2eb66a2
+6
@@ -33684,6 +33684,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("functionContractScript.kts")
|
||||||
|
public void testFunctionContractScript() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/script/functionContractScript.kts");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("imports.kts")
|
@TestMetadata("imports.kts")
|
||||||
public void testImports() throws Exception {
|
public void testImports() throws Exception {
|
||||||
|
|||||||
+6
@@ -33684,6 +33684,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("functionContractScript.kts")
|
||||||
|
public void testFunctionContractScript() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/script/functionContractScript.kts");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("imports.kts")
|
@TestMetadata("imports.kts")
|
||||||
public void testImports() throws Exception {
|
public void testImports() throws Exception {
|
||||||
|
|||||||
+6
@@ -31512,6 +31512,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("functionContractScript.kts")
|
||||||
|
public void testFunctionContractScript() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/script/functionContractScript.kts");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("imports.kts")
|
@TestMetadata("imports.kts")
|
||||||
public void testImports() throws Exception {
|
public void testImports() throws Exception {
|
||||||
|
|||||||
+3
-1
@@ -286,7 +286,9 @@ abstract class FirAbstractContractResolveTransformerDispatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun transformScript(script: FirScript, data: ResolutionMode): FirScript {
|
override fun transformScript(script: FirScript, data: ResolutionMode): FirScript {
|
||||||
return script
|
return withScript(script) {
|
||||||
|
transformDeclarationContent(script, data) as FirScript
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transformAnonymousObject(
|
override fun transformAnonymousObject(
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
inline fun <T> exactlyOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> atLeastOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.AT_LEAST_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> atMostOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
val a: String
|
||||||
|
exactlyOnce { <!VAL_REASSIGNMENT!>a<!> = "" }
|
||||||
|
a.length
|
||||||
|
|
||||||
|
val b: String
|
||||||
|
atLeastOnce { <!VAL_REASSIGNMENT, VAL_REASSIGNMENT!>b<!> = "" }
|
||||||
|
b.length
|
||||||
|
|
||||||
|
<!MUST_BE_INITIALIZED!>val c: String<!>
|
||||||
|
atMostOnce { <!VAL_REASSIGNMENT!>c<!> = "" }
|
||||||
|
<!UNINITIALIZED_VARIABLE!>c<!>.length
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// !OPT_IN: kotlin.contracts.ExperimentalContracts
|
||||||
|
|
||||||
|
import kotlin.contracts.*
|
||||||
|
|
||||||
|
inline fun <T> exactlyOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> atLeastOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.AT_LEAST_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> atMostOnce(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) }
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
val a: String
|
||||||
|
exactlyOnce { <!CAPTURED_MEMBER_VAL_INITIALIZATION!>a<!> = "" }
|
||||||
|
a.length
|
||||||
|
|
||||||
|
val b: String
|
||||||
|
atLeastOnce { <!VAL_REASSIGNMENT!>b<!> = "" }
|
||||||
|
b.length
|
||||||
|
|
||||||
|
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val c: String<!>
|
||||||
|
atMostOnce { <!CAPTURED_MEMBER_VAL_INITIALIZATION!>c<!> = "" }
|
||||||
|
<!UNINITIALIZED_VARIABLE!>c<!>.length
|
||||||
+2
-2
@@ -29,7 +29,7 @@ val b: String = inPlaceRun { <!UNINITIALIZED_VARIABLE!>b<!> }
|
|||||||
val c: String = notInPlaceRun { c }
|
val c: String = notInPlaceRun { c }
|
||||||
|
|
||||||
val d: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>d<!>)
|
val d: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>d<!>)
|
||||||
val e: String by inPlaceDelegate { e }
|
val e: String by inPlaceDelegate { <!UNINITIALIZED_VARIABLE!>e<!> }
|
||||||
val f: String by notInPlaceDelegate { f }
|
val f: String by notInPlaceDelegate { f }
|
||||||
|
|
||||||
val g: Int
|
val g: Int
|
||||||
@@ -53,6 +53,6 @@ val t: String = <!UNINITIALIZED_VARIABLE!>z<!>
|
|||||||
val u: String = inPlaceRun { <!UNINITIALIZED_VARIABLE!>z<!> }
|
val u: String = inPlaceRun { <!UNINITIALIZED_VARIABLE!>z<!> }
|
||||||
val v: String = notInPlaceRun { z }
|
val v: String = notInPlaceRun { z }
|
||||||
val w: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>z<!>)
|
val w: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>z<!>)
|
||||||
val x: String by inPlaceDelegate { z }
|
val x: String by inPlaceDelegate { <!UNINITIALIZED_VARIABLE!>z<!> }
|
||||||
val y: String by notInPlaceDelegate { z }
|
val y: String by notInPlaceDelegate { z }
|
||||||
val z: String = "VALUE"
|
val z: String = "VALUE"
|
||||||
|
|||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// KT-64074
|
|
||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -WRONG_INVOCATION_KIND
|
|
||||||
// WITH_STDLIB
|
|
||||||
|
|
||||||
import kotlin.contracts.ExperimentalContracts
|
|
||||||
import kotlin.contracts.InvocationKind
|
|
||||||
import kotlin.contracts.contract
|
|
||||||
import kotlin.properties.ReadOnlyProperty
|
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
|
||||||
inline fun <T> inPlaceRun(block: () -> T): T {
|
|
||||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
|
||||||
return block()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> notInPlaceRun(block: () -> T): T = null!!
|
|
||||||
|
|
||||||
fun <T> simpleDelegate(value: T): ReadOnlyProperty<Any?, T> = null!!
|
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
|
||||||
fun <T> inPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> {
|
|
||||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
|
||||||
return null!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> notInPlaceDelegate(block: () -> T): ReadOnlyProperty<Any?, T> = null!!
|
|
||||||
|
|
||||||
val a: String = <!UNINITIALIZED_VARIABLE!>a<!>
|
|
||||||
val b: String = inPlaceRun { <!UNINITIALIZED_VARIABLE!>b<!> }
|
|
||||||
val c: String = notInPlaceRun { c }
|
|
||||||
|
|
||||||
val d: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>d<!>)
|
|
||||||
val e: String by inPlaceDelegate { <!UNINITIALIZED_VARIABLE!>e<!> }
|
|
||||||
val f: String by notInPlaceDelegate { f }
|
|
||||||
|
|
||||||
val g: Int
|
|
||||||
val h = 1.also { <!VAL_REASSIGNMENT!>g<!> = 2 }
|
|
||||||
<!MUST_BE_INITIALIZED!>val i: Int<!>
|
|
||||||
val j by lazy { <!CAPTURED_VAL_INITIALIZATION, VAL_REASSIGNMENT!>i<!> = 2; 1 }
|
|
||||||
val k: Int
|
|
||||||
get() {
|
|
||||||
<!VAL_REASSIGNMENT!>i<!> = 3
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
val l: Comparator<String> = object : Comparator<String> {
|
|
||||||
val delegate: Comparator<String> get() = n
|
|
||||||
override fun compare(o1: String, o2: String): Int = delegate.compare(o1, o2)
|
|
||||||
}
|
|
||||||
val m: Comparator<String> = object : Comparator<String> by <!UNINITIALIZED_VARIABLE!>n<!> {}
|
|
||||||
val n: Comparator<String> = Comparator { _, _ -> 0 }
|
|
||||||
|
|
||||||
val t: String = <!UNINITIALIZED_VARIABLE!>z<!>
|
|
||||||
val u: String = inPlaceRun { <!UNINITIALIZED_VARIABLE!>z<!> }
|
|
||||||
val v: String = notInPlaceRun { z }
|
|
||||||
val w: String by simpleDelegate(<!UNINITIALIZED_VARIABLE!>z<!>)
|
|
||||||
val x: String by inPlaceDelegate { <!UNINITIALIZED_VARIABLE!>z<!> }
|
|
||||||
val y: String by notInPlaceDelegate { z }
|
|
||||||
val z: String = "VALUE"
|
|
||||||
Generated
+6
@@ -33684,6 +33684,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
runTest("compiler/testData/diagnostics/tests/script/destructuringDeclarationsScript.kts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("functionContractScript.kts")
|
||||||
|
public void testFunctionContractScript() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/script/functionContractScript.kts");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("imports.kts")
|
@TestMetadata("imports.kts")
|
||||||
public void testImports() throws Exception {
|
public void testImports() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user