Skip to content

Commit d9bd992

Browse files
cypressiousSpace Team
authored andcommitted
[FIR] Report PARAMETER_NAME_CHANGED_ON_OVERRIDE for context parameters
#KT-81684 Fixed
1 parent a7e5a94 commit d9bd992

File tree

8 files changed

+94
-12
lines changed

8 files changed

+94
-12
lines changed

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

Lines changed: 12 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: 12 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: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/testData/resolve/contextParameters/diagnostics/contextParameterNameChanged.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ interface I2 {
1111
context(y: Int) fun foo()
1212
}
1313

14-
interface I3 : I1, I2
14+
<!DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES!>interface I3<!> : I1, I2
1515

1616
class C1 : I1 {
17-
context(xx: Int) override fun foo() {}
17+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>xx<!>: Int) override fun foo() {}
1818
}
1919

2020
// FILE: test2.kt
@@ -28,10 +28,10 @@ interface I2 {
2828
context(_: Int) fun foo()
2929
}
3030

31-
interface I3 : I1, I2
31+
<!DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES!>interface I3<!> : I1, I2
3232

3333
class C1 : I1 {
34-
context(xx: Int) override fun foo() {}
34+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>xx<!>: Int) override fun foo() {}
3535
}
3636

3737
// FILE: test3.kt
@@ -45,10 +45,10 @@ interface I2 {
4545
context(_: Int) fun foo()
4646
}
4747

48-
interface I3 : I1, I2
48+
<!DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES!>interface I3<!> : I1, I2
4949

5050
class C1 : I1 {
51-
context(_: Int) override fun foo() {}
51+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>_<!>: Int) override fun foo() {}
5252
}
5353

5454
/* GENERATED_FIR_TAGS: classDeclaration, functionDeclaration, functionDeclarationWithContext, interfaceDeclaration,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN_PIPELINE_TILL: FRONTEND
2+
// LANGUAGE: +ContextParameters +ExplicitContextArguments
3+
4+
interface I {
5+
context(s: String)
6+
fun simple1()
7+
8+
context(s: String)
9+
fun unnamedInOverride()
10+
11+
context(_: String)
12+
fun unnamedInBase()
13+
}
14+
15+
class C : I {
16+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>string<!>: String)
17+
override fun simple1() {}
18+
19+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>_<!>: String)
20+
override fun unnamedInOverride() {}
21+
22+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>s<!>: String)
23+
override fun unnamedInBase() {}
24+
}
25+
26+
fun test(c: C) {
27+
c.<!NO_CONTEXT_ARGUMENT!>simple1<!>(<!NAMED_PARAMETER_NOT_FOUND!>s<!> = "")
28+
c.simple1(string = "")
29+
30+
c.<!NO_CONTEXT_ARGUMENT!>unnamedInOverride<!>(<!NAMED_PARAMETER_NOT_FOUND!>s<!> = "")
31+
32+
c.unnamedInBase(s = "")
33+
}
34+
35+
/* GENERATED_FIR_TAGS: classDeclaration, functionDeclaration, functionDeclarationWithContext, interfaceDeclaration,
36+
stringLiteral */

compiler/fir/analysis-tests/testData/resolve/contextParameters/overrides/genericPropertyOverride.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ abstract class Base<T> {
1717
}
1818

1919
class Child : Base<String>() {
20-
context(child: RChild)
20+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>child<!>: RChild)
2121
override fun <RChild> String.foo(): Int? = 1
2222

23-
context(child: RChild)
23+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>child<!>: RChild)
2424
override fun <RChild> String.foo(t: String): Int? = 1
2525

2626
context(child: RChild)

compiler/fir/analysis-tests/testData/resolve/contextParameters/overrides/nameCanBeChangedInOverride.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open class Base {
1212
}
1313

1414
class Derived : Base() {
15-
context(x: A)
15+
context(<!PARAMETER_NAME_CHANGED_ON_OVERRIDE!>x<!>: A)
1616
override fun foo() {}
1717

1818
context(x: A)

compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/declarationUtils.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,22 @@ val FirCallableSymbol<*>.hasExplicitReturnType: Boolean
148148

149149
fun FirNamedFunctionSymbol.checkValueParameterNamesWith(
150150
otherFunctionSymbol: FirNamedFunctionSymbol,
151-
reportAction: (currentParameter: FirValueParameterSymbol, conflictingParameter: FirValueParameterSymbol, parameterIndex: Int) -> Unit
151+
reportAction: (currentParameter: FirValueParameterSymbol, conflictingParameter: FirValueParameterSymbol, parameterIndex: Int) -> Unit,
152152
) {
153-
// We don't handle context parameters here because we specifically allow renaming them in overrides (KT-75815).
154-
val valueParameterPairs = valueParameterSymbols.zip(otherFunctionSymbol.valueParameterSymbols)
153+
checkValueParameterNamesWith(valueParameterSymbols, otherFunctionSymbol.valueParameterSymbols, reportAction)
154+
checkValueParameterNamesWith(contextParameterSymbols, otherFunctionSymbol.contextParameterSymbols, reportAction)
155+
}
156+
157+
@OptIn(SymbolInternals::class)
158+
private fun checkValueParameterNamesWith(
159+
symbols: List<FirValueParameterSymbol>,
160+
otherSymbols: List<FirValueParameterSymbol>,
161+
reportAction: (FirValueParameterSymbol, FirValueParameterSymbol, Int) -> Unit,
162+
) {
163+
val valueParameterPairs = symbols.zip(otherSymbols)
155164
for ((index, valueParameterPair) in valueParameterPairs.withIndex()) {
156165
val (currentValueParameter, otherValueParameter) = valueParameterPair
166+
if (currentValueParameter.fir.isLegacyContextReceiver() || otherValueParameter.fir.isLegacyContextReceiver()) continue
157167
if (currentValueParameter.name != otherValueParameter.name) {
158168
reportAction(currentValueParameter, otherValueParameter, index)
159169
}

0 commit comments

Comments
 (0)