Skip to content

Commit 03f9caa

Browse files
cypressiousSpace Team
authored andcommitted
[Tests] Add tests for explicit context argument passing
#KT-81684
1 parent 55f29cc commit 03f9caa

File tree

37 files changed

+971
-0
lines changed

37 files changed

+971
-0
lines changed

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLDiagnosticsFirTestGenerated.java

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLPartialDiagnosticsFirTestGenerated.java

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/low-level-api-fir/tests-gen/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedDiagnosticsFirTestGenerated.java

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN_PIPELINE_TILL: FRONTEND
2+
// LANGUAGE: +ContextParameters -ExplicitContextArguments
3+
4+
class A
5+
class B
6+
7+
context(a: A) fun needsA() { }
8+
context(b: B) fun needsB() { }
9+
context(a: A, b: B) fun needsBoth() { }
10+
11+
fun explicit() {
12+
<!NO_CONTEXT_ARGUMENT!>needsA<!>(<!NAMED_PARAMETER_NOT_FOUND!>a<!> = A())
13+
<!NO_CONTEXT_ARGUMENT!>needsB<!>(<!NAMED_PARAMETER_NOT_FOUND!>b<!> = B())
14+
<!NO_CONTEXT_ARGUMENT, NO_CONTEXT_ARGUMENT!>needsBoth<!>(<!NAMED_PARAMETER_NOT_FOUND!>a<!> = A(), <!NAMED_PARAMETER_NOT_FOUND!>b<!> = B())
15+
}
16+
17+
/* GENERATED_FIR_TAGS: classDeclaration, functionDeclaration, functionDeclarationWithContext */
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN_PIPELINE_TILL: FRONTEND
2+
// LANGUAGE: +ContextParameters +ExplicitContextArguments
3+
// FILE: J.java
4+
public class J implements I {
5+
public void foo(String x) {}
6+
}
7+
8+
// FILE: J2.java
9+
public class J2 implements I, I2 {
10+
public void foo(String x) {}
11+
}
12+
13+
// FILE: J3.java
14+
public class J3 implements I, I3 {
15+
public void foo(String x) {}
16+
}
17+
18+
// FILE: test.kt
19+
interface I {
20+
context(s: String) fun foo()
21+
}
22+
23+
interface I2 {
24+
context(s2: String) fun foo()
25+
}
26+
27+
interface I3 {
28+
context(_: String) fun foo()
29+
}
30+
31+
fun test(j: J, j2: J2, j3: J3) {
32+
j.foo(s = "")
33+
j2.foo(<!NAME_FOR_AMBIGUOUS_PARAMETER!>s<!> = "")
34+
j2.foo(<!NAME_FOR_AMBIGUOUS_PARAMETER!>s2<!> = "")
35+
j3.foo(s = "")
36+
}
37+
38+
/* GENERATED_FIR_TAGS: functionDeclaration, functionDeclarationWithContext, interfaceDeclaration, javaType,
39+
stringLiteral */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN_PIPELINE_TILL: FRONTEND
2+
// LANGUAGE: +ContextParameters +ExplicitContextArguments
3+
4+
context(c: String)
5+
fun foo(s: String, s2: String) {}
6+
7+
fun test() {
8+
foo(s = "", "", c = "")
9+
foo(c = "2", <!MIXING_NAMED_AND_POSITIONAL_ARGUMENTS!>""<!>, <!NO_VALUE_FOR_PARAMETER!>s = "")<!>
10+
}
11+
12+
/* GENERATED_FIR_TAGS: functionDeclaration, functionDeclarationWithContext, stringLiteral */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN_PIPELINE_TILL: FRONTEND
2+
// LANGUAGE: +ContextParameters +ExplicitContextArguments
3+
4+
class C {
5+
context(s: String)
6+
operator fun get(i: Int) = ""
7+
8+
context(s: String)
9+
operator fun invoke(i: Int) = ""
10+
}
11+
12+
fun test(c: C, f: context(String) () -> Unit) {
13+
<!NO_CONTEXT_ARGUMENT!>c[1, <!ASSIGNMENT_IN_EXPRESSION_CONTEXT, TOO_MANY_ARGUMENTS!><!UNRESOLVED_REFERENCE!>s<!> = ""<!>]<!>
14+
15+
c(1, s = "")
16+
f(<!NAMED_ARGUMENTS_NOT_ALLOWED!>p1<!> = "")
17+
}
18+
19+
/* GENERATED_FIR_TAGS: assignment, classDeclaration, functionDeclaration, functionDeclarationWithContext, integerLiteral,
20+
operator, stringLiteral */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FILE: optional.kt
2+
public final class A : R|kotlin/Any| {
3+
public constructor(): R|A| {
4+
super<R|kotlin/Any|>()
5+
}
6+
7+
}
8+
context(a: R|A|)
9+
public final fun foo(): R|kotlin/Unit| {
10+
}
11+
public final fun foo(a: R|A| = R|/A.A|(), x: R|kotlin/Int| = Int(1)): R|kotlin/Unit| {
12+
}
13+
public final fun test(): R|kotlin/Unit| {
14+
R|/foo|()
15+
context(R|/A.A|()) R|/foo|()
16+
R|/foo|(R|/A.A|(), Int(2))
17+
}

0 commit comments

Comments
 (0)