[FIR] Make rendering of properties for diagnostics more user-friendly
#KT-60137 Fixed
This commit is contained in:
committed by
Space Team
parent
b5ea059861
commit
ed6948959c
+6
@@ -23974,6 +23974,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationThroughDestructuring.kt")
|
||||
public void testRedeclarationThroughDestructuring() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SyntheticAndNotSynthetic.kt")
|
||||
public void testSyntheticAndNotSynthetic() throws Exception {
|
||||
|
||||
+6
@@ -23974,6 +23974,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationThroughDestructuring.kt")
|
||||
public void testRedeclarationThroughDestructuring() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SyntheticAndNotSynthetic.kt")
|
||||
public void testSyntheticAndNotSynthetic() throws Exception {
|
||||
|
||||
Vendored
+3
-3
@@ -4,7 +4,7 @@ C:
|
||||
[Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0]
|
||||
[SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
|
||||
[Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2]
|
||||
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0]
|
||||
[Source]: private final var name: R|kotlin/String| from Use site scope of /C [id: 0]
|
||||
|
||||
D:
|
||||
[Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0]
|
||||
@@ -12,6 +12,6 @@ D:
|
||||
[Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0]
|
||||
[SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
|
||||
[Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2]
|
||||
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Java enhancement scope for /D [id: 0]
|
||||
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0]
|
||||
[Source]: private final var name: R|kotlin/String| from Java enhancement scope for /D [id: 0]
|
||||
[Source]: private final var name: R|kotlin/String| from Use site scope of /C [id: 0]
|
||||
|
||||
|
||||
+6
@@ -23974,6 +23974,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationThroughDestructuring.kt")
|
||||
public void testRedeclarationThroughDestructuring() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SyntheticAndNotSynthetic.kt")
|
||||
public void testSyntheticAndNotSynthetic() throws Exception {
|
||||
|
||||
+6
@@ -23980,6 +23980,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationThroughDestructuring.kt")
|
||||
public void testRedeclarationThroughDestructuring() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SyntheticAndNotSynthetic.kt")
|
||||
public void testSyntheticAndNotSynthetic() throws Exception {
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ object FirDiagnosticRenderers {
|
||||
callArgumentsRenderer = FirCallNoArgumentsRenderer(),
|
||||
modifierRenderer = FirPartialModifierRenderer(),
|
||||
valueParameterRenderer = FirValueParameterRendererNoDefaultValue(),
|
||||
declarationRenderer = FirDeclarationRenderer("local ")
|
||||
).renderElementAsString(symbol.fir, trim = true)
|
||||
is FirTypeParameterSymbol -> symbol.name.asString()
|
||||
else -> "???"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.renderer
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirVariable
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirLazyBlock
|
||||
@@ -23,6 +24,17 @@ class FirBodyRenderer {
|
||||
renderBody(function.body)
|
||||
}
|
||||
|
||||
fun render(variable: FirVariable) {
|
||||
variable.initializer?.let {
|
||||
printer.print(" = ")
|
||||
it.accept(visitor)
|
||||
}
|
||||
variable.delegate?.let {
|
||||
printer.print("by ")
|
||||
it.accept(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
fun renderBody(block: FirBlock?, additionalStatements: List<FirStatement> = emptyList()) {
|
||||
if (block == null) return
|
||||
when (block) {
|
||||
|
||||
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirErrorConstructor
|
||||
import org.jetbrains.kotlin.fir.isCatchParameter
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
|
||||
open class FirDeclarationRenderer {
|
||||
open class FirDeclarationRenderer(
|
||||
private val localVariablePrefix: String = "l",
|
||||
) {
|
||||
|
||||
internal lateinit var components: FirRendererComponents
|
||||
protected val printer get() = components.printer
|
||||
@@ -40,7 +42,7 @@ open class FirDeclarationRenderer {
|
||||
if (declaration.isCatchParameter == true) {
|
||||
""
|
||||
} else {
|
||||
val prefix = if (declaration.isLocal) "l" else ""
|
||||
val prefix = if (declaration.isLocal) localVariablePrefix else ""
|
||||
prefix + if (declaration.isVal) "val" else "var"
|
||||
}
|
||||
}
|
||||
@@ -61,4 +63,4 @@ open class FirDeclarationRenderer {
|
||||
|
||||
protected open fun FirDeclaration.renderDeclarationAttributes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,14 +305,7 @@ class FirRenderer(
|
||||
|
||||
override fun visitVariable(variable: FirVariable) {
|
||||
visitCallableDeclaration(variable)
|
||||
variable.initializer?.let {
|
||||
print(" = ")
|
||||
it.accept(this)
|
||||
}
|
||||
variable.delegate?.let {
|
||||
print("by ")
|
||||
it.accept(this)
|
||||
}
|
||||
bodyRenderer?.render(variable)
|
||||
}
|
||||
|
||||
override fun visitField(field: FirField) {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
/test.kt:(154,158): error: Overload resolution ambiguity between candidates: [static field SOME: String = String(Some), static enum entry SOME: SomeEnum]
|
||||
/test.kt:(154,158): error: Overload resolution ambiguity between candidates: [static field SOME: String, static enum entry SOME: SomeEnum]
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
/test.kt:(160,164): error: Overload resolution ambiguity between candidates: [static field SOME: String = String(Some), static enum entry SOME: SomeEnum]
|
||||
/test.kt:(160,164): error: Overload resolution ambiguity between candidates: [static field SOME: String, static enum entry SOME: SomeEnum]
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/RedeclarationThroughDestructuring.kt:5:14: error: conflicting declarations: val b: String, val b: Int
|
||||
val (b, b) = e
|
||||
^
|
||||
/RedeclarationThroughDestructuring.kt:5:17: error: conflicting declarations: val b: String, val b: Int
|
||||
val (b, b) = e
|
||||
^
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
/RedeclarationThroughDestructuring.fir.kt:(133,134): error: Conflicting declarations: [local val b: String, local val b: Int]
|
||||
|
||||
/RedeclarationThroughDestructuring.fir.kt:(136,137): error: Conflicting declarations: [local val b: String, local val b: Int]
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
data class Example(val a: String, val b: Int) {
|
||||
fun testRedeclaration(e: Example){
|
||||
val (<!REDECLARATION!>b<!>, <!REDECLARATION!>b<!>) = e
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
data class Example(val a: String, val b: Int) {
|
||||
fun testRedeclaration(e: Example){
|
||||
val (<!REDECLARATION!>b<!>, <!NAME_SHADOWING, REDECLARATION!>b<!>) = e
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+6
@@ -25006,6 +25006,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/overloadsFromCurrentAndSuperClassWithReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclarationThroughDestructuring.kt")
|
||||
public void testRedeclarationThroughDestructuring() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/overload/RedeclarationThroughDestructuring.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SyntheticAndNotSynthetic.kt")
|
||||
public void testSyntheticAndNotSynthetic() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user