IDE: Add test for message of VAL_OR_VAR_ON_*_PARAMETER diagnostic.
Also fall back to getting parameter descriptor if property descriptor not found for `val/var` parameters. ^KTIJ-13030 Fixed
This commit is contained in:
committed by
teamcityserver
parent
23605e08be
commit
2c18406632
@@ -39,6 +39,9 @@ fun KtDeclaration.resolveToDescriptorIfAny(
|
||||
val context = analyze(resolutionFacade, bodyResolveMode)
|
||||
return if (this is KtParameter && hasValOrVar()) {
|
||||
context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
||||
// It is incorrect to have `val/var` parameters outside the primary constructor (e.g., `fun foo(val x: Int)`)
|
||||
// but we still want to try to resolve in such cases.
|
||||
?: context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
|
||||
} else {
|
||||
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
|
||||
}
|
||||
|
||||
Generated
+5
@@ -795,5 +795,10 @@ public class FirKotlinHighlightingPassTestGenerated extends AbstractFirKotlinHig
|
||||
public void testOperatorCallDiagnosticsOnInOperator() throws Exception {
|
||||
runTest("idea/testData/checker/diagnosticsMessage/operatorCallDiagnosticsOnInOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("valOrVarOnParameter.kt")
|
||||
public void testValOrVarOnParameter() throws Exception {
|
||||
runTest("idea/testData/checker/diagnosticsMessage/valOrVarOnParameter.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A {
|
||||
constructor(<warning descr="[VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER] 'val' on secondary constructor parameter is not allowed">val</warning> <warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Int) {
|
||||
for (<warning descr="[VAL_OR_VAR_ON_LOOP_PARAMETER] 'val' on loop parameter is not allowed">val</warning> z in 1..4) {}
|
||||
}
|
||||
|
||||
fun foo(<warning descr="[VAL_OR_VAR_ON_FUN_PARAMETER] 'var' on function parameter is not allowed">var</warning> <warning descr="[UNUSED_PARAMETER] Parameter 'y' is never used">y</warning>: Int) {
|
||||
try {
|
||||
for (<warning descr="[VAL_OR_VAR_ON_LOOP_PARAMETER] 'var' on loop parameter is not allowed">var</warning> (<warning descr="[UNUSED_VARIABLE] Variable 'i' is never used">i</warning>, <warning descr="[UNUSED_VARIABLE] Variable 'j' is never used">j</warning>) in listOf(1 to 4)) {}
|
||||
} catch (<warning descr="[VAL_OR_VAR_ON_CATCH_PARAMETER] 'val' on catch parameter is not allowed">val</warning> e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A {
|
||||
constructor(<error descr="[VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER] 'val' on secondary constructor parameter is not allowed">val</error> <warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Int) {
|
||||
for (<error descr="[VAL_OR_VAR_ON_LOOP_PARAMETER] 'val' on loop parameter is not allowed">val</error> z in 1..4) {}
|
||||
}
|
||||
|
||||
fun foo(<error descr="[VAL_OR_VAR_ON_FUN_PARAMETER] 'var' on function parameter is not allowed">var</error> <warning descr="[UNUSED_PARAMETER] Parameter 'y' is never used">y</warning>: Int) {
|
||||
try {
|
||||
for (<error descr="[VAL_OR_VAR_ON_LOOP_PARAMETER] 'var' on loop parameter is not allowed">var</error> (<warning descr="[UNUSED_VARIABLE] Variable 'i' is never used">i</warning>, <warning descr="[UNUSED_VARIABLE] Variable 'j' is never used">j</warning>) in listOf(1 to 4)) {}
|
||||
} catch (<error descr="[VAL_OR_VAR_ON_CATCH_PARAMETER] 'val' on catch parameter is not allowed">val</error> e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -940,5 +940,10 @@ public class KotlinHighlightingPassTestGenerated extends AbstractKotlinHighlight
|
||||
public void testOperatorCallDiagnosticsOnInOperator() throws Exception {
|
||||
runTest("idea/testData/checker/diagnosticsMessage/operatorCallDiagnosticsOnInOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("valOrVarOnParameter.kt")
|
||||
public void testValOrVarOnParameter() throws Exception {
|
||||
runTest("idea/testData/checker/diagnosticsMessage/valOrVarOnParameter.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user