Skip to content

Commit 1acbf07

Browse files
cypressiousSpace Team
authored and
Space Team
committed
[FIR] Improve positioning strategy of WRONG_NUMBER_OF_TYPE_ARGUMENTS
#KT-59188 Fixed
1 parent b16ceab commit 1acbf07

File tree

10 files changed

+48
-42
lines changed

10 files changed

+48
-42
lines changed

compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
734734
parameter<String>("place")
735735
}
736736
val TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED by error<PsiElement>()
737-
val WRONG_NUMBER_OF_TYPE_ARGUMENTS by error<PsiElement> {
737+
val WRONG_NUMBER_OF_TYPE_ARGUMENTS by error<PsiElement>(PositioningStrategy.TYPE_ARGUMENT_LIST_OR_SELF) {
738738
parameter<Int>("expectedCount")
739739
parameter<FirClassLikeSymbol<*>>("classifier")
740740
}

compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/RegularDiagnosticData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum class PositioningStrategy(private val strategy: String? = null) {
121121
EXPECT_ACTUAL_MODIFIER,
122122
TYPEALIAS_TYPE_REFERENCE,
123123
SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS_DIAGNOSTIC,
124+
TYPE_ARGUMENT_LIST_OR_SELF,
124125
;
125126

126127
val expressionToCreate get() = "SourceElementPositioningStrategies.${strategy ?: name}"

compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ object FirErrors {
452452
val UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION: KtDiagnosticFactory2<ConeKotlinType, ConeKotlinType> by error2<PsiElement, ConeKotlinType, ConeKotlinType>()
453453
val TYPE_ARGUMENTS_NOT_ALLOWED: KtDiagnosticFactory1<String> by error1<PsiElement, String>()
454454
val TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED: KtDiagnosticFactory0 by error0<PsiElement>()
455-
val WRONG_NUMBER_OF_TYPE_ARGUMENTS: KtDiagnosticFactory2<Int, FirClassLikeSymbol<*>> by error2<PsiElement, Int, FirClassLikeSymbol<*>>()
455+
val WRONG_NUMBER_OF_TYPE_ARGUMENTS: KtDiagnosticFactory2<Int, FirClassLikeSymbol<*>> by error2<PsiElement, Int, FirClassLikeSymbol<*>>(SourceElementPositioningStrategies.TYPE_ARGUMENT_LIST_OR_SELF)
456456
val NO_TYPE_ARGUMENTS_ON_RHS: KtDiagnosticFactory2<Int, FirClassLikeSymbol<*>> by error2<PsiElement, Int, FirClassLikeSymbol<*>>()
457457
val OUTER_CLASS_ARGUMENTS_REQUIRED: KtDiagnosticFactory1<FirClassLikeSymbol<*>> by error1<PsiElement, FirClassLikeSymbol<*>>()
458458
val TYPE_PARAMETERS_IN_OBJECT: KtDiagnosticFactory0 by error0<PsiElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)

compiler/frontend.common-psi/src/org/jetbrains/kotlin/diagnostics/LightTreePositioningStrategies.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,19 @@ object LightTreePositioningStrategies {
12731273
return markElement(nodeToMark, startOffset, endOffset, tree, node)
12741274
}
12751275
}
1276+
1277+
val TYPE_ARGUMENT_LIST_OR_SELF: LightTreePositioningStrategy = object : LightTreePositioningStrategy() {
1278+
override fun mark(
1279+
node: LighterASTNode,
1280+
startOffset: Int,
1281+
endOffset: Int,
1282+
tree: FlyweightCapableTreeStructure<LighterASTNode>,
1283+
): List<TextRange> {
1284+
val nodeToMark = tree.findChildByType(node, KtNodeTypes.TYPE_ARGUMENT_LIST) ?: node
1285+
1286+
return markElement(nodeToMark, startOffset, endOffset, tree, node)
1287+
}
1288+
}
12761289
}
12771290

12781291
fun KtSourceElement.hasValOrVar(): Boolean =

compiler/frontend.common-psi/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,4 +1126,11 @@ object PositioningStrategies {
11261126
return super.mark(result)
11271127
}
11281128
}
1129+
1130+
val TYPE_ARGUMENT_LIST_OR_SELF = object : PositioningStrategy<PsiElement>() {
1131+
override fun mark(element: PsiElement): List<TextRange> {
1132+
element.getChildOfType<KtTypeArgumentList>()?.let { return markElement(it) }
1133+
return super.mark(element)
1134+
}
1135+
}
11291136
}

compiler/frontend.common-psi/src/org/jetbrains/kotlin/diagnostics/SourceElementPositioningStrategies.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,9 @@ object SourceElementPositioningStrategies {
407407
LightTreePositioningStrategies.SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS_DIAGNOSTIC,
408408
PositioningStrategies.SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS_DIAGNOSTIC,
409409
)
410+
411+
val TYPE_ARGUMENT_LIST_OR_SELF = SourceElementPositioningStrategy(
412+
LightTreePositioningStrategies.TYPE_ARGUMENT_LIST_OR_SELF,
413+
PositioningStrategies.TYPE_ARGUMENT_LIST_OR_SELF,
414+
)
410415
}

compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.fir.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Foo<I, J : Number, K> {
88

99
fun test_1() {
1010
val a = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<!>::value
11-
val b = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<String><!>::value
11+
val b = Foo<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String><!>::value
1212
val c = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<!>::genericValue
13-
val d = <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<String><!>::genericValue
13+
val d = Foo<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String><!>::genericValue
1414
}

compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.fir.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ typealias SomeUnusedAlias<T> = Some
55

66
fun test_1() {
77
Some::foo
8-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Some<Int><!>::foo
8+
Some<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>::foo
99

1010
SomeAlias::foo
11-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>SomeAlias<Int><!>::foo
11+
SomeAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>::foo
1212

1313
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>SomeUnusedAlias<!>::foo
1414
SomeUnusedAlias<Int>::foo
1515
SomeUnusedAlias<out Int>::foo
1616
SomeUnusedAlias<in Int>::foo
1717
SomeUnusedAlias<*>::foo
18-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>SomeUnusedAlias<Int, Int><!>::foo
18+
SomeUnusedAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int><!>::foo
1919
}
2020

2121
// ----------------------------------------------------------------
@@ -34,34 +34,34 @@ fun test_2() {
3434
Inv<<!UPPER_BOUND_VIOLATED!>out Int<!>>::foo
3535
Inv<out String>::foo
3636
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inv<!>::foo
37-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inv<String, String><!>::foo
37+
Inv<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String><!>::foo
3838

3939
InvAlias<String>::foo
4040
InvAlias<<!UPPER_BOUND_VIOLATED!>Int<!>>::foo
4141
InvAlias<*>::foo
4242
InvAlias<<!UPPER_BOUND_VIOLATED!>out Int<!>>::foo
4343
InvAlias<out String>::foo
4444
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvAlias<!>::foo
45-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvAlias<String, String><!>::foo
45+
InvAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String><!>::foo
4646

4747
InvUnusedCorrectAlias<String>::foo
4848
InvUnusedCorrectAlias<Int>::foo
4949
InvUnusedCorrectAlias<*>::foo
5050
InvUnusedCorrectAlias<out Int>::foo
5151
InvUnusedCorrectAlias<out String>::foo
5252
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvUnusedCorrectAlias<!>::foo
53-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvUnusedCorrectAlias<String, String><!>::foo
53+
InvUnusedCorrectAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String><!>::foo
5454

5555
InvUnusedIncorrectAlias<String>::foo
5656
InvUnusedIncorrectAlias<Int>::foo
5757
InvUnusedIncorrectAlias<*>::foo
5858
InvUnusedIncorrectAlias<out Int>::foo
5959
InvUnusedIncorrectAlias<out String>::foo
6060
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvUnusedIncorrectAlias<!>::foo
61-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvUnusedIncorrectAlias<String, String><!>::foo
61+
InvUnusedIncorrectAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String><!>::foo
6262

6363
InvSpecificAlias::foo
64-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>InvSpecificAlias<String, String><!>::foo
64+
InvSpecificAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><String, String><!>::foo
6565
}
6666

6767
// ----------------------------------------------------------------
@@ -86,7 +86,7 @@ fun test_3() {
8686
BoundedPair<in String, in Int>::foo
8787
BoundedPair<<!UPPER_BOUND_VIOLATED!>in Int<!>, in Int>::foo
8888
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPair<!>::foo
89-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPair<Int, Int, Int><!>::foo
89+
BoundedPair<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
9090

9191
BoundedPairAlias<String, Int>::foo
9292
BoundedPairAlias<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>::foo
@@ -96,7 +96,7 @@ fun test_3() {
9696
BoundedPairAlias<in String, in Int>::foo
9797
BoundedPairAlias<<!UPPER_BOUND_VIOLATED!>in Int<!>, in Int>::foo
9898
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairAlias<!>::foo
99-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairAlias<Int, Int, Int><!>::foo
99+
BoundedPairAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
100100

101101
BoundedPairInverted<String, <!UPPER_BOUND_VIOLATED!>Int<!>>::foo
102102
BoundedPairInverted<Int, <!UPPER_BOUND_VIOLATED!>Int<!>>::foo
@@ -106,7 +106,7 @@ fun test_3() {
106106
BoundedPairInverted<in String, <!UPPER_BOUND_VIOLATED!>in Int<!>>::foo
107107
BoundedPairInverted<in Int, <!UPPER_BOUND_VIOLATED!>in Int<!>>::foo
108108
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairInverted<!>::foo
109-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairInverted<Int, Int, Int><!>::foo
109+
BoundedPairInverted<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
110110

111111
BoundedPairFirstFixedAlias<Int>::foo
112112
BoundedPairFirstFixedAlias<Int>::foo
@@ -116,7 +116,7 @@ fun test_3() {
116116
BoundedPairFirstFixedAlias<in String>::foo
117117
BoundedPairFirstFixedAlias<in Int>::foo
118118
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairFirstFixedAlias<!>::foo
119-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairFirstFixedAlias<Int, Int><!>::foo
119+
BoundedPairFirstFixedAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int><!>::foo
120120

121121
BoundedPairSecondFixedAlias<<!UPPER_BOUND_VIOLATED!>Int<!>>::foo
122122
BoundedPairSecondFixedAlias<<!UPPER_BOUND_VIOLATED!>Int<!>>::foo
@@ -126,7 +126,7 @@ fun test_3() {
126126
BoundedPairSecondFixedAlias<in String>::foo
127127
BoundedPairSecondFixedAlias<<!UPPER_BOUND_VIOLATED!>in Int<!>>::foo
128128
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSecondFixedAlias<!>::foo
129-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSecondFixedAlias<Int, Int><!>::foo
129+
BoundedPairSecondFixedAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int><!>::foo
130130

131131
BoundedPairFirstUnusedAlias<String, Int>::foo
132132
BoundedPairFirstUnusedAlias<Int, Int>::foo
@@ -136,7 +136,7 @@ fun test_3() {
136136
BoundedPairFirstUnusedAlias<in String, in Int>::foo
137137
BoundedPairFirstUnusedAlias<in Int, in Int>::foo
138138
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairFirstUnusedAlias<!>::foo
139-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairFirstUnusedAlias<Int, Int, Int><!>::foo
139+
BoundedPairFirstUnusedAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
140140

141141
BoundedPairSecondUnusedAlias<String, Int>::foo
142142
BoundedPairSecondUnusedAlias<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>::foo
@@ -146,7 +146,7 @@ fun test_3() {
146146
BoundedPairSecondUnusedAlias<in String, in Int>::foo
147147
BoundedPairSecondUnusedAlias<<!UPPER_BOUND_VIOLATED!>in Int<!>, in Int>::foo
148148
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSecondUnusedAlias<!>::foo
149-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSecondUnusedAlias<Int, Int, Int><!>::foo
149+
BoundedPairSecondUnusedAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
150150

151151
BoundedPairBothAlias<String, Int>::foo
152152
BoundedPairBothAlias<Int, Int>::foo
@@ -156,7 +156,7 @@ fun test_3() {
156156
BoundedPairBothAlias<in String, in Int>::foo
157157
BoundedPairBothAlias<in Int, in Int>::foo
158158
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairBothAlias<!>::foo
159-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairBothAlias<Int, Int, Int><!>::foo
159+
BoundedPairBothAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
160160

161161
BoundedPairSpecificAlias<String, Int>::foo
162162
BoundedPairSpecificAlias<Int, Int>::foo
@@ -166,5 +166,5 @@ fun test_3() {
166166
BoundedPairSpecificAlias<in String, in Int>::foo
167167
BoundedPairSpecificAlias<in Int, in Int>::foo
168168
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSpecificAlias<!>::foo
169-
<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>BoundedPairSpecificAlias<Int, Int, Int><!>::foo
169+
BoundedPairSpecificAlias<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int, Int, Int><!>::foo
170170
}

compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// WITH_STDLIB
23
// !DIAGNOSTICS: -UNUSED_VARIABLE
34

0 commit comments

Comments
 (0)