[FIR] Remove or replace whole expressions in FIR diagnostic messages
FIR expressions rendered by FirRenderer don't look very nice in error messages anyway, and additionally, they can become arbitrarily large, so we shouldn't use them in messages. #KT-59449 Fixed
This commit is contained in:
committed by
Space Team
parent
0f0f0d604f
commit
6318da0f02
+10
-10
@@ -3586,8 +3586,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirErrors.SENSELESS_COMPARISON) { firDiagnostic ->
|
||||
SenselessComparisonImpl(
|
||||
firDiagnostic.a.source!!.psi as KtExpression,
|
||||
firDiagnostic.b,
|
||||
firDiagnostic.a,
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -3621,18 +3620,20 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirErrors.UNSAFE_INFIX_CALL) { firDiagnostic ->
|
||||
UnsafeInfixCallImpl(
|
||||
firDiagnostic.a.source!!.psi as KtExpression,
|
||||
firDiagnostic.b,
|
||||
firDiagnostic.c.source!!.psi as KtExpression,
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic.b.source!!.psi as KtExpression,
|
||||
firDiagnostic.c,
|
||||
firDiagnostic.d.source!!.psi as KtExpression,
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.UNSAFE_OPERATOR_CALL) { firDiagnostic ->
|
||||
UnsafeOperatorCallImpl(
|
||||
firDiagnostic.a.source!!.psi as KtExpression,
|
||||
firDiagnostic.b,
|
||||
firDiagnostic.c.source!!.psi as KtExpression,
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic.b.source!!.psi as KtExpression,
|
||||
firDiagnostic.c,
|
||||
firDiagnostic.d.source!!.psi as KtExpression,
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -4315,8 +4316,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirErrors.INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE) { firDiagnostic ->
|
||||
InvalidDefaultFunctionalParameterForInlineImpl(
|
||||
firDiagnostic.a.source!!.psi as KtExpression,
|
||||
firSymbolBuilder.buildSymbol(firDiagnostic.b),
|
||||
firSymbolBuilder.buildSymbol(firDiagnostic.a),
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
|
||||
+2
-2
@@ -2506,7 +2506,6 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
interface SenselessComparison : KtFirDiagnostic<KtExpression> {
|
||||
override val diagnosticClass get() = SenselessComparison::class
|
||||
val expression: KtExpression
|
||||
val compareResult: Boolean
|
||||
}
|
||||
|
||||
@@ -2531,6 +2530,7 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
interface UnsafeInfixCall : KtFirDiagnostic<KtExpression> {
|
||||
override val diagnosticClass get() = UnsafeInfixCall::class
|
||||
val receiverType: KtType
|
||||
val receiverExpression: KtExpression
|
||||
val operator: String
|
||||
val argumentExpression: KtExpression
|
||||
@@ -2538,6 +2538,7 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
interface UnsafeOperatorCall : KtFirDiagnostic<KtExpression> {
|
||||
override val diagnosticClass get() = UnsafeOperatorCall::class
|
||||
val receiverType: KtType
|
||||
val receiverExpression: KtExpression
|
||||
val operator: String
|
||||
val argumentExpression: KtExpression
|
||||
@@ -3011,7 +3012,6 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
interface InvalidDefaultFunctionalParameterForInline : KtFirDiagnostic<KtElement> {
|
||||
override val diagnosticClass get() = InvalidDefaultFunctionalParameterForInline::class
|
||||
val defaultValue: KtExpression
|
||||
val parameter: KtSymbol
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -3018,7 +3018,6 @@ internal class UnreachableCodeImpl(
|
||||
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.UnreachableCode
|
||||
|
||||
internal class SenselessComparisonImpl(
|
||||
override val expression: KtExpression,
|
||||
override val compareResult: Boolean,
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
@@ -3048,6 +3047,7 @@ internal class UnsafeImplicitInvokeCallImpl(
|
||||
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.UnsafeImplicitInvokeCall
|
||||
|
||||
internal class UnsafeInfixCallImpl(
|
||||
override val receiverType: KtType,
|
||||
override val receiverExpression: KtExpression,
|
||||
override val operator: String,
|
||||
override val argumentExpression: KtExpression,
|
||||
@@ -3056,6 +3056,7 @@ internal class UnsafeInfixCallImpl(
|
||||
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.UnsafeInfixCall
|
||||
|
||||
internal class UnsafeOperatorCallImpl(
|
||||
override val receiverType: KtType,
|
||||
override val receiverExpression: KtExpression,
|
||||
override val operator: String,
|
||||
override val argumentExpression: KtExpression,
|
||||
@@ -3629,7 +3630,6 @@ internal class NonInternalPublishedApiImpl(
|
||||
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.NonInternalPublishedApi
|
||||
|
||||
internal class InvalidDefaultFunctionalParameterForInlineImpl(
|
||||
override val defaultValue: KtExpression,
|
||||
override val parameter: KtSymbol,
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
|
||||
+6
@@ -29742,6 +29742,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexExpression.kt")
|
||||
public void testComplexExpression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/senselessComparison/complexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitType.kt")
|
||||
public void testNoExplicitType() throws Exception {
|
||||
|
||||
+6
@@ -29742,6 +29742,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexExpression.kt")
|
||||
public void testComplexExpression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/senselessComparison/complexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitType.kt")
|
||||
public void testNoExplicitType() throws Exception {
|
||||
|
||||
+6
@@ -29742,6 +29742,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexExpression.kt")
|
||||
public void testComplexExpression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/senselessComparison/complexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitType.kt")
|
||||
public void testNoExplicitType() throws Exception {
|
||||
|
||||
+6
@@ -29838,6 +29838,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexExpression.kt")
|
||||
public void testComplexExpression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/senselessComparison/complexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitType.kt")
|
||||
public void testNoExplicitType() throws Exception {
|
||||
|
||||
+2
-2
@@ -1236,7 +1236,6 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
parameter<Set<KtSourceElement>>("unreachable")
|
||||
}
|
||||
val SENSELESS_COMPARISON by warning<KtExpression> {
|
||||
parameter<FirExpression>("expression")
|
||||
parameter<Boolean>("compareResult")
|
||||
}
|
||||
val SENSELESS_NULL_IN_WHEN by warning<KtElement>()
|
||||
@@ -1252,11 +1251,13 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
parameter<ConeKotlinType>("receiverType")
|
||||
}
|
||||
val UNSAFE_INFIX_CALL by error<KtExpression>(PositioningStrategy.REFERENCE_BY_QUALIFIED) {
|
||||
parameter<ConeKotlinType>("receiverType")
|
||||
parameter<FirExpression>("receiverExpression")
|
||||
parameter<String>("operator")
|
||||
parameter<FirExpression>("argumentExpression")
|
||||
}
|
||||
val UNSAFE_OPERATOR_CALL by error<KtExpression>(PositioningStrategy.REFERENCE_BY_QUALIFIED) {
|
||||
parameter<ConeKotlinType>("receiverType")
|
||||
parameter<FirExpression>("receiverExpression")
|
||||
parameter<String>("operator")
|
||||
parameter<FirExpression>("argumentExpression")
|
||||
@@ -1520,7 +1521,6 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val NON_INTERNAL_PUBLISHED_API by error<KtElement>()
|
||||
|
||||
val INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE by error<KtElement>() {
|
||||
parameter<FirExpression>("defaultValue")
|
||||
parameter<FirValueParameterSymbol>("parameter")
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -645,15 +645,15 @@ object FirErrors {
|
||||
val VARIABLE_WITH_NO_TYPE_NO_INITIALIZER by error0<KtVariableDeclaration>(SourceElementPositioningStrategies.DECLARATION_NAME)
|
||||
val INITIALIZATION_BEFORE_DECLARATION by error1<KtExpression, FirBasedSymbol<*>>()
|
||||
val UNREACHABLE_CODE by warning2<KtElement, Set<KtSourceElement>, Set<KtSourceElement>>(SourceElementPositioningStrategies.UNREACHABLE_CODE)
|
||||
val SENSELESS_COMPARISON by warning2<KtExpression, FirExpression, Boolean>()
|
||||
val SENSELESS_COMPARISON by warning1<KtExpression, Boolean>()
|
||||
val SENSELESS_NULL_IN_WHEN by warning0<KtElement>()
|
||||
val TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM by error0<KtExpression>()
|
||||
|
||||
// Nullability
|
||||
val UNSAFE_CALL by error2<PsiElement, ConeKotlinType, FirExpression?>(SourceElementPositioningStrategies.DOT_BY_QUALIFIED)
|
||||
val UNSAFE_IMPLICIT_INVOKE_CALL by error1<PsiElement, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
val UNSAFE_INFIX_CALL by error3<KtExpression, FirExpression, String, FirExpression>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
val UNSAFE_OPERATOR_CALL by error3<KtExpression, FirExpression, String, FirExpression>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
val UNSAFE_INFIX_CALL by error4<KtExpression, ConeKotlinType, FirExpression, String, FirExpression>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
val UNSAFE_OPERATOR_CALL by error4<KtExpression, ConeKotlinType, FirExpression, String, FirExpression>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
val ITERATOR_ON_NULLABLE by error0<KtExpression>()
|
||||
val UNNECESSARY_SAFE_CALL by warning1<PsiElement, ConeKotlinType>(SourceElementPositioningStrategies.SAFE_ACCESS)
|
||||
val SAFE_CALL_WILL_CHANGE_NULLABILITY by warning0<KtSafeQualifiedExpression>(SourceElementPositioningStrategies.CALL_ELEMENT_WITH_DOT)
|
||||
@@ -770,7 +770,7 @@ object FirErrors {
|
||||
val DECLARATION_CANT_BE_INLINED by error0<KtDeclaration>(SourceElementPositioningStrategies.INLINE_FUN_MODIFIER)
|
||||
val OVERRIDE_BY_INLINE by warning0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE)
|
||||
val NON_INTERNAL_PUBLISHED_API by error0<KtElement>()
|
||||
val INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE by error2<KtElement, FirExpression, FirValueParameterSymbol>()
|
||||
val INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE by error1<KtElement, FirValueParameterSymbol>()
|
||||
val REIFIED_TYPE_PARAMETER_IN_OVERRIDE by error0<KtElement>(SourceElementPositioningStrategies.REIFIED_MODIFIER)
|
||||
val INLINE_PROPERTY_WITH_BACKING_FIELD by error0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE)
|
||||
val ILLEGAL_INLINE_PARAMETER_MODIFIER by error0<KtElement>(SourceElementPositioningStrategies.INLINE_PARAMETER_MODIFIER)
|
||||
|
||||
-1
@@ -420,7 +420,6 @@ object FirInlineDeclarationChecker : FirFunctionChecker() {
|
||||
reporter.reportOn(
|
||||
defaultValue.source,
|
||||
FirErrors.INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE,
|
||||
defaultValue,
|
||||
param.symbol,
|
||||
context
|
||||
)
|
||||
|
||||
+1
-1
@@ -273,7 +273,7 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() {
|
||||
if (expression.source?.elementType != KtNodeTypes.BINARY_EXPRESSION && type === lType && !compareResult) {
|
||||
reporter.reportOn(expression.source, FirErrors.SENSELESS_NULL_IN_WHEN, context)
|
||||
} else {
|
||||
reporter.reportOn(expression.source, FirErrors.SENSELESS_COMPARISON, expression, compareResult, context)
|
||||
reporter.reportOn(expression.source, FirErrors.SENSELESS_COMPARISON, compareResult, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-6
@@ -11,10 +11,14 @@ import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers
|
||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.ContextIndependentParameterRenderer
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.calleeReference
|
||||
import org.jetbrains.kotlin.fir.expressions.unwrapSmartcastExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||
import org.jetbrains.kotlin.fir.renderer.*
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
@@ -65,12 +69,17 @@ object FirDiagnosticRenderers {
|
||||
}
|
||||
}
|
||||
|
||||
val VARIABLE_NAME = Renderer { symbol: FirVariableSymbol<*> ->
|
||||
symbol.name.asString()
|
||||
val CALLEE_NAME = Renderer { element: FirExpression ->
|
||||
when (val reference = element.unwrapSmartcastExpression().calleeReference) {
|
||||
is FirNamedReference -> reference.name.asString()
|
||||
is FirThisReference -> "this"
|
||||
is FirSuperReference -> "super"
|
||||
else -> "???"
|
||||
}
|
||||
}
|
||||
|
||||
val FIR = Renderer { element: FirElement ->
|
||||
element.render()
|
||||
val VARIABLE_NAME = Renderer { symbol: FirVariableSymbol<*> ->
|
||||
symbol.name.asString()
|
||||
}
|
||||
|
||||
val DECLARATION_NAME = Renderer { symbol: FirBasedSymbol<*> ->
|
||||
|
||||
+17
-17
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.commaSeparated
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.LanguageFeatureMessageRenderer
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.AMBIGUOUS_CALLS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.CALLEE_NAME
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.DECLARATION_NAME
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FIR
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FQ_NAMES_IN_TYPES
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FUNCTIONAL_TYPE_KINDS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.SYMBOLS_ON_NEWLINE_WITH_INDENT
|
||||
@@ -1254,7 +1254,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
SMARTCAST_IMPOSSIBLE,
|
||||
"Smart cast to ''{0}'' is impossible, because ''{1}'' is a {2}",
|
||||
RENDER_TYPE,
|
||||
FIR,
|
||||
CALLEE_NAME,
|
||||
TO_STRING,
|
||||
NOT_RENDERED
|
||||
)
|
||||
@@ -1367,8 +1367,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
)
|
||||
map.put(
|
||||
INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE,
|
||||
"Invalid default value for inline parameter: ''{0}''. Only lambdas, anonymous functions, and callable references are supported",
|
||||
FIR,
|
||||
"Invalid default value for inline function parameter. Only lambdas, anonymous functions, and callable references are supported",
|
||||
DECLARATION_NAME
|
||||
)
|
||||
map.put(
|
||||
@@ -1898,36 +1897,37 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(LEAKED_IN_PLACE_LAMBDA, "Leaked in-place lambda: {0}", SYMBOL)
|
||||
map.put(FirErrors.WRONG_IMPLIES_CONDITION, "Wrong implies condition")
|
||||
map.put(UNREACHABLE_CODE, "Unreachable code", NOT_RENDERED, NOT_RENDERED)
|
||||
map.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", FIR, TO_STRING)
|
||||
map.put(SENSELESS_COMPARISON, "Condition is always ''{0}''", TO_STRING)
|
||||
map.put(SENSELESS_NULL_IN_WHEN, "Expression under 'when' is never equal to null")
|
||||
|
||||
// Nullability
|
||||
map.put(USELESS_CALL_ON_NOT_NULL, "Unsafe call on not null")
|
||||
map.put(
|
||||
UNSAFE_CALL,
|
||||
"Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type {0}",
|
||||
"Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ''{0}''.",
|
||||
RENDER_TYPE,
|
||||
NOT_RENDERED,
|
||||
NOT_RENDERED
|
||||
)
|
||||
map.put(
|
||||
UNSAFE_IMPLICIT_INVOKE_CALL,
|
||||
"Reference has a nullable type ''{0}'', use explicit \"?.invoke\" to make a function-like call instead.",
|
||||
"Reference has a nullable type ''{0}'', use explicit ''?.invoke'' to make a function-like call instead.",
|
||||
RENDER_TYPE
|
||||
)
|
||||
map.put(
|
||||
UNSAFE_INFIX_CALL,
|
||||
"Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " +
|
||||
"Use ''?.''-qualified call instead",
|
||||
FIR,
|
||||
TO_STRING,
|
||||
FIR,
|
||||
"Infix call is not allowed on a nullable receiver of type ''{0}''. Use ''?.''-qualified call instead.",
|
||||
RENDER_TYPE,
|
||||
NOT_RENDERED,
|
||||
NOT_RENDERED,
|
||||
NOT_RENDERED,
|
||||
)
|
||||
map.put(
|
||||
UNSAFE_OPERATOR_CALL,
|
||||
"Operator call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. ",
|
||||
FIR,
|
||||
TO_STRING,
|
||||
FIR,
|
||||
"Operator call is not allowed on a nullable receiver of type ''{0}''. Use ''?.''-qualified call instead.",
|
||||
RENDER_TYPE,
|
||||
NOT_RENDERED,
|
||||
NOT_RENDERED,
|
||||
NOT_RENDERED,
|
||||
)
|
||||
map.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE)
|
||||
map.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression")
|
||||
|
||||
+2
@@ -200,6 +200,7 @@ private fun mapUnsafeCallError(
|
||||
return if (operationSource?.getChild(KtTokens.IDENTIFIER) != null) {
|
||||
FirErrors.UNSAFE_INFIX_CALL.createOn(
|
||||
source,
|
||||
rootCause.actualType,
|
||||
receiverExpression,
|
||||
candidateFunctionName!!.asString(),
|
||||
singleArgument,
|
||||
@@ -207,6 +208,7 @@ private fun mapUnsafeCallError(
|
||||
} else {
|
||||
FirErrors.UNSAFE_OPERATOR_CALL.createOn(
|
||||
source,
|
||||
rootCause.actualType,
|
||||
receiverExpression,
|
||||
candidateFunctionName!!.asString(),
|
||||
singleArgument,
|
||||
|
||||
@@ -70,3 +70,10 @@ fun FirReference.isError(): Boolean {
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun FirReference.toNameString(): String? = when (this) {
|
||||
is FirNamedReference -> name.asString()
|
||||
is FirThisReference -> "this"
|
||||
is FirSuperReference -> "super"
|
||||
else -> null
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
/complexExpression.fir.kt:(75,121): warning: Condition is always 'false'
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
fun String?.repro(): Boolean {
|
||||
return <!SENSELESS_COMPARISON!>this?.let {
|
||||
return false
|
||||
} == true<!>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
fun String?.repro(): Boolean {
|
||||
return this?.let {
|
||||
return false
|
||||
} == true
|
||||
}
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
/B.kt:(133,134): error: Smart cast to 'kotlin/String' is impossible, because 'this@R|/Derived|.R|/Base.x|' is a public API property declared in different module
|
||||
/B.kt:(133,134): error: Smart cast to 'kotlin/String' is impossible, because 'x' is a public API property declared in different module
|
||||
|
||||
/B.kt:(265,268): error: Smart cast to 'kotlin/String' is impossible, because 'R|<local>/i|.R|/Base.x|' is a public API property declared in different module
|
||||
/B.kt:(265,268): error: Smart cast to 'kotlin/String' is impossible, because 'x' is a public API property declared in different module
|
||||
|
||||
Generated
+6
@@ -30670,6 +30670,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("complexExpression.kt")
|
||||
public void testComplexExpression() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/senselessComparison/complexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitType.kt")
|
||||
public void testNoExplicitType() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user