Skip to content

Commit bc7d6b1

Browse files
cypressiousSpace Team
authored and
Space Team
committed
[FIR] Don't report EXTENSION_SHADOWED_BY_MEMBER if type parameter count is different
#KT-75169
1 parent a2fea2b commit bc7d6b1

10 files changed

+85
-6
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ sealed class FirExtensionShadowedByMemberChecker(kind: MppCheckerKind) : FirCall
151151
if (varargParameterPosition != extension.varargParameterPosition) return false
152152
if (extension.isOperator && !isOperator) return false
153153
if (extension.isInfix && !isInfix) return false
154+
if (extension.typeParameterSymbols.size != typeParameterSymbols.size) return false
154155

155156
val helper = context.session.declarationOverloadabilityHelper
156157
val memberSignature = helper.createSignature(this)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// ISSUE: KT-54483, KT-75169
3+
// WITH_STDLIB
4+
5+
abstract class Cache {
6+
fun get(): Int = 10
7+
fun get2(): Int = 10
8+
fun <T> get3(): Int = 10
9+
fun <T : CharSequence> get4(): Int = 10
10+
}
11+
12+
inline fun <reified T> Cache.get() = 10
13+
fun <T> Cache.get2() = 10
14+
fun <T, R> Cache.get3() = 10
15+
fun <T : List<String>> Cache.<!EXTENSION_SHADOWED_BY_MEMBER!>get4<!>() = 10

compiler/testData/diagnostics/tests/extensionShadowedByMember.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN_PIPELINE_TILL: BACKEND
2-
// FIR_IDENTICAL
32
// ISSUE: KT-54483, KT-75169
43
// WITH_STDLIB
54

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// DIAGNOSTICS: -UNUSED_PARAMETER
3+
4+
interface Test1 {
5+
fun test1() {}
6+
}
7+
fun Test1.<!EXTENSION_SHADOWED_BY_MEMBER!>test1<!>() {}
8+
9+
interface Test2 {
10+
fun test2(x: String) {}
11+
}
12+
fun Test2.test2(x: Any) {}
13+
14+
interface Test3 {
15+
fun test3(x: Any) {}
16+
}
17+
fun Test3.<!EXTENSION_SHADOWED_BY_MEMBER!>test3<!>(x: String) {}
18+
fun <T : Any?> Test3.test3(x: T) {}
19+
20+
interface Test4 {
21+
fun <T> test4(x: T) {}
22+
}
23+
fun Test4.test4(x: String) {}
24+
25+
interface Test5 {
26+
fun <T> test5(x: T) {}
27+
}
28+
fun <T : Number> Test5.<!EXTENSION_SHADOWED_BY_MEMBER!>test5<!>(x: T) {}
29+
30+
interface Test6 {
31+
fun <T : List<Any>> test6(x: T) {}
32+
}
33+
fun <T : Set<Any>> Test6.test6(x: T) {}
34+
35+
interface Test7 {
36+
fun test7()
37+
}
38+
39+
fun Test7?.test7() {}
40+
41+
interface Test8 {
42+
fun test8()
43+
}
44+
45+
typealias NullableTest8 = Test8?
46+
47+
fun NullableTest8.test8() {}

compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberFun.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN_PIPELINE_TILL: BACKEND
2-
// FIR_IDENTICAL
32
// DIAGNOSTICS: -UNUSED_PARAMETER
43

54
interface Test1 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN_PIPELINE_TILL: BACKEND
2+
// DIAGNOSTICS: -UNUSED_PARAMETER
3+
4+
interface WithInvoke {
5+
operator fun invoke()
6+
operator fun invoke(s: String)
7+
operator fun <T> invoke(x: T, y: Int)
8+
fun invoke(i: Int)
9+
}
10+
11+
interface Test1 {
12+
val test1: WithInvoke
13+
}
14+
15+
fun Test1.<!EXTENSION_FUNCTION_SHADOWED_BY_MEMBER_PROPERTY_WITH_INVOKE!>test1<!>() {}
16+
fun Test1.<!EXTENSION_FUNCTION_SHADOWED_BY_MEMBER_PROPERTY_WITH_INVOKE!>test1<!>(s: String) {}
17+
fun Test1.test1(i: Int) {}
18+
fun Test1.test1(x: Any, y: Int) {}
19+
fun <T : Number> Test1.<!EXTENSION_FUNCTION_SHADOWED_BY_MEMBER_PROPERTY_WITH_INVOKE!>test1<!>(x: T, y: Int) {}

compiler/testData/diagnostics/tests/redeclarations/shadowedExtension/extensionFunShadowedByMemberPropertyWithInvoke.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN_PIPELINE_TILL: BACKEND
2-
// FIR_IDENTICAL
32
// DIAGNOSTICS: -UNUSED_PARAMETER
43

54
interface WithInvoke {

compiler/testData/diagnostics/tests/testsWithJava21/globalExtensionForHiddenInDeclaringMethod.fir.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ abstract class A : List<Any> {
55
}
66
}
77

8-
fun <T> List<T>.<!EXTENSION_SHADOWED_BY_MEMBER!>getFirst<!>(): Int = 1
8+
fun <T> List<T>.getFirst(): Int = 1
99

1010
fun test(l: A){
1111
consumeInt(<!ARGUMENT_TYPE_MISMATCH!>l.<!DEPRECATION!>getFirst<!>()<!>)

compiler/testData/diagnostics/tests/testsWithJava21/memberExtensionForHiddenInDeclaringMethod.fir.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract class A : List<Any> {
88
abstract class B : List<Any>
99

1010
class Test {
11-
fun <T> List<T>.<!EXTENSION_SHADOWED_BY_MEMBER!>getFirst<!>() = 1
11+
fun <T> List<T>.getFirst() = 1
1212

1313
fun test(a: A, b: B){
1414
consumeInt(<!ARGUMENT_TYPE_MISMATCH!>a.<!DEPRECATION!>getFirst<!>()<!>)

compiler/testData/diagnostics/tests/testsWithJava21/otherHiddenInDeclaring.fir.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun String.repeat(n: Int) = 1
1717
fun String.describeConstable() = 1
1818
fun String.resolveConstantDesc(lookup: MethodHandles.Lookup) = 1
1919

20-
fun <E : Enum<E>> Enum<E>.<!EXTENSION_SHADOWED_BY_MEMBER!>describeConstable<!>() = 1
20+
fun <E : Enum<E>> Enum<E>.describeConstable() = 1
2121

2222
enum class MyEnum { E }
2323

0 commit comments

Comments
 (0)