[FE] Support local contextual declarations
This commit is contained in:
committed by
TeamCityServer
parent
43d11c7c4b
commit
875f4ea31c
+6
@@ -10600,6 +10600,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localDeclaration.kt")
|
||||||
|
public void testLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/localDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("manyReceivers.kt")
|
@TestMetadata("manyReceivers.kt")
|
||||||
public void testManyReceivers() throws Exception {
|
public void testManyReceivers() throws Exception {
|
||||||
|
|||||||
+6
@@ -16169,6 +16169,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/inferGenericPropertyType.kt");
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/inferGenericPropertyType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localDeclaration.kt")
|
||||||
|
public void testLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/localDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("plusAssign.kt")
|
@TestMetadata("plusAssign.kt")
|
||||||
public void testPlusAssign() throws Exception {
|
public void testPlusAssign() throws Exception {
|
||||||
|
|||||||
@@ -1094,6 +1094,9 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing {
|
|||||||
*/
|
*/
|
||||||
private boolean parseLocalDeclaration(boolean rollbackIfDefinitelyNotExpression, boolean isScriptTopLevel) {
|
private boolean parseLocalDeclaration(boolean rollbackIfDefinitelyNotExpression, boolean isScriptTopLevel) {
|
||||||
PsiBuilder.Marker decl = mark();
|
PsiBuilder.Marker decl = mark();
|
||||||
|
if (atSet(CONTEXT_KEYWORD)) {
|
||||||
|
myKotlinParsing.parseContextReceiverList();
|
||||||
|
}
|
||||||
KotlinParsing.ModifierDetector detector = new KotlinParsing.ModifierDetector();
|
KotlinParsing.ModifierDetector detector = new KotlinParsing.ModifierDetector();
|
||||||
myKotlinParsing.parseModifierList(detector, DEFAULT, TokenSet.EMPTY);
|
myKotlinParsing.parseModifierList(detector, DEFAULT, TokenSet.EMPTY);
|
||||||
|
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
* contextReceiverList
|
* contextReceiverList
|
||||||
* : "context" "(" (label? typeReference{","})+ ")"
|
* : "context" "(" (label? typeReference{","})+ ")"
|
||||||
*/
|
*/
|
||||||
private void parseContextReceiverList() {
|
public void parseContextReceiverList() {
|
||||||
assert _at(CONTEXT_KEYWORD);
|
assert _at(CONTEXT_KEYWORD);
|
||||||
PsiBuilder.Marker contextReceiverList = mark();
|
PsiBuilder.Marker contextReceiverList = mark();
|
||||||
advance(); // CONTEXT_KEYWORD
|
advance(); // CONTEXT_KEYWORD
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val ok get() = "OK"
|
||||||
|
}
|
||||||
|
class B : A
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
context(A) fun result() = ok
|
||||||
|
return with(B()) {
|
||||||
|
result()
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
interface A {
|
||||||
|
fun f() {}
|
||||||
|
}
|
||||||
|
class B : A
|
||||||
|
|
||||||
|
fun testLocalFunction() {
|
||||||
|
context(A)
|
||||||
|
fun local() {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
with(B()) {
|
||||||
|
local()
|
||||||
|
}
|
||||||
|
local()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testLocalClass() {
|
||||||
|
context(A)
|
||||||
|
class Local {
|
||||||
|
fun local() {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with(B()) {
|
||||||
|
Local().local()
|
||||||
|
}
|
||||||
|
Local()
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
interface A {
|
||||||
|
fun f() {}
|
||||||
|
}
|
||||||
|
class B : A
|
||||||
|
|
||||||
|
fun testLocalFunction() {
|
||||||
|
context(A)
|
||||||
|
fun local() {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
with(B()) {
|
||||||
|
local()
|
||||||
|
}
|
||||||
|
<!NO_CONTEXT_RECEIVER!>local()<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testLocalClass() {
|
||||||
|
context(A)
|
||||||
|
class Local {
|
||||||
|
fun local() {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with(B()) {
|
||||||
|
Local().local()
|
||||||
|
}
|
||||||
|
<!NO_CONTEXT_RECEIVER!>Local()<!>
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun testLocalClass(): kotlin.Unit
|
||||||
|
public fun testLocalFunction(): kotlin.Unit
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open fun f(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class B : A {
|
||||||
|
public constructor B()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun f(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
Generated
+6
@@ -10606,6 +10606,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localDeclaration.kt")
|
||||||
|
public void testLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/localDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("manyReceivers.kt")
|
@TestMetadata("manyReceivers.kt")
|
||||||
public void testManyReceivers() throws Exception {
|
public void testManyReceivers() throws Exception {
|
||||||
|
|||||||
+6
@@ -16169,6 +16169,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/inferGenericPropertyType.kt");
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/inferGenericPropertyType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localDeclaration.kt")
|
||||||
|
public void testLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/localDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("plusAssign.kt")
|
@TestMetadata("plusAssign.kt")
|
||||||
public void testPlusAssign() throws Exception {
|
public void testPlusAssign() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user