K1: add a language feature to negate new errors from DiagnosticReporterByTrackingStrategy
Related to KT-55055, KT-55056, KT-55079, KT-57854
This commit is contained in:
committed by
Space Team
parent
4188bca9b8
commit
94c94d0605
+12
@@ -36736,6 +36736,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inconsistentTypeInference_noReporting.kt")
|
||||||
|
public void testInconsistentTypeInference_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("incorrectCalls.kt")
|
@TestMetadata("incorrectCalls.kt")
|
||||||
public void testIncorrectCalls() throws Exception {
|
public void testIncorrectCalls() throws Exception {
|
||||||
@@ -36808,6 +36814,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("upperBoundViolation_noReporting.kt")
|
||||||
|
public void testUpperBoundViolation_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||||
|
|||||||
+12
@@ -36736,6 +36736,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inconsistentTypeInference_noReporting.kt")
|
||||||
|
public void testInconsistentTypeInference_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("incorrectCalls.kt")
|
@TestMetadata("incorrectCalls.kt")
|
||||||
public void testIncorrectCalls() throws Exception {
|
public void testIncorrectCalls() throws Exception {
|
||||||
@@ -36808,6 +36814,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("upperBoundViolation_noReporting.kt")
|
||||||
|
public void testUpperBoundViolation_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||||
|
|||||||
+12
@@ -36736,6 +36736,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inconsistentTypeInference_noReporting.kt")
|
||||||
|
public void testInconsistentTypeInference_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("incorrectCalls.kt")
|
@TestMetadata("incorrectCalls.kt")
|
||||||
public void testIncorrectCalls() throws Exception {
|
public void testIncorrectCalls() throws Exception {
|
||||||
@@ -36808,6 +36814,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("upperBoundViolation_noReporting.kt")
|
||||||
|
public void testUpperBoundViolation_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||||
|
|||||||
+12
@@ -36832,6 +36832,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inconsistentTypeInference_noReporting.kt")
|
||||||
|
public void testInconsistentTypeInference_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("incorrectCalls.kt")
|
@TestMetadata("incorrectCalls.kt")
|
||||||
public void testIncorrectCalls() throws Exception {
|
public void testIncorrectCalls() throws Exception {
|
||||||
@@ -36904,6 +36910,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("upperBoundViolation_noReporting.kt")
|
||||||
|
public void testUpperBoundViolation_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||||
|
|||||||
+28
-11
@@ -185,7 +185,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
private fun unknownError(diagnostic: KotlinCallDiagnostic, onTarget: String) {
|
private fun unknownError(diagnostic: KotlinCallDiagnostic, onTarget: String) {
|
||||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||||
throw AssertionError("$onTarget should not be called with ${diagnostic::class.java}")
|
throw AssertionError("$onTarget should not be called with ${diagnostic::class.java}")
|
||||||
} else {
|
} else if (reportAdditionalErrors) {
|
||||||
trace.report(
|
trace.report(
|
||||||
NEW_INFERENCE_UNKNOWN_ERROR.on(
|
NEW_INFERENCE_UNKNOWN_ERROR.on(
|
||||||
psiKotlinCall.psiCall.callElement,
|
psiKotlinCall.psiCall.callElement,
|
||||||
@@ -567,15 +567,17 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
val originalCall = (position as DeclaredUpperBoundConstraintPositionImpl).kotlinCall
|
val originalCall = (position as DeclaredUpperBoundConstraintPositionImpl).kotlinCall
|
||||||
val typeParameterDescriptor = position.typeParameter
|
val typeParameterDescriptor = position.typeParameter
|
||||||
val ownerDescriptor = typeParameterDescriptor.containingDeclaration
|
val ownerDescriptor = typeParameterDescriptor.containingDeclaration
|
||||||
trace.reportDiagnosticOnce(
|
if (reportAdditionalErrors) {
|
||||||
UPPER_BOUND_VIOLATION_IN_CONSTRAINT.on(
|
trace.reportDiagnosticOnce(
|
||||||
(originalCall as PSIKotlinCall).psiCall.callElement,
|
UPPER_BOUND_VIOLATION_IN_CONSTRAINT.on(
|
||||||
typeParameterDescriptor.name,
|
(originalCall as PSIKotlinCall).psiCall.callElement,
|
||||||
ownerDescriptor.name,
|
typeParameterDescriptor.name,
|
||||||
error.upperKotlinType,
|
ownerDescriptor.name,
|
||||||
error.lowerKotlinType
|
error.upperKotlinType,
|
||||||
|
error.lowerKotlinType
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
is DelegatedPropertyConstraintPosition<*> -> {
|
is DelegatedPropertyConstraintPosition<*> -> {
|
||||||
// DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, reported later
|
// DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, reported later
|
||||||
@@ -590,7 +592,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
SimpleConstraintSystemConstraintPosition -> {
|
SimpleConstraintSystemConstraintPosition -> {
|
||||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||||
throw AssertionError("Constraint error in unexpected position: $position")
|
throw AssertionError("Constraint error in unexpected position: $position")
|
||||||
} else {
|
} else if (reportAdditionalErrors) {
|
||||||
report(
|
report(
|
||||||
TYPE_MISMATCH_IN_CONSTRAINT.on(
|
TYPE_MISMATCH_IN_CONSTRAINT.on(
|
||||||
psiKotlinCall.psiCall.callElement,
|
psiKotlinCall.psiCall.callElement,
|
||||||
@@ -629,7 +631,11 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
|
|
||||||
val expression = argument.psiExpression ?: run {
|
val expression = argument.psiExpression ?: run {
|
||||||
val psiCall = (selectorCall as? PSIKotlinCall)?.psiCall ?: psiKotlinCall.psiCall
|
val psiCall = (selectorCall as? PSIKotlinCall)?.psiCall ?: psiKotlinCall.psiCall
|
||||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ProperTypeInferenceConstraintsProcessing)) {
|
// Note: we don't report RECEIVER_TYPE_MISMATCH w/out ProperTypeInferenceConstraintsProcessing
|
||||||
|
// See KT-57854. This is needed for intellij.go.tests (recursive generics case) compilation with K1
|
||||||
|
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ProperTypeInferenceConstraintsProcessing) &&
|
||||||
|
reportAdditionalErrors
|
||||||
|
) {
|
||||||
report(
|
report(
|
||||||
RECEIVER_TYPE_MISMATCH.on(
|
RECEIVER_TYPE_MISMATCH.on(
|
||||||
psiCall.calleeExpression ?: psiCall.callElement, error.upperKotlinType, error.lowerKotlinType
|
psiCall.calleeExpression ?: psiCall.callElement, error.upperKotlinType, error.lowerKotlinType
|
||||||
@@ -657,6 +663,17 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
report(typeMismatchDiagnostic.on(deparenthesized, error.upperKotlinType, error.lowerKotlinType))
|
report(typeMismatchDiagnostic.on(deparenthesized, error.upperKotlinType, error.lowerKotlinType))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should we report additional errors appeared in Kotlin compiler 1.9.0 or not
|
||||||
|
*
|
||||||
|
* This property appeared in Kotlin compiler 1.9.0, after we discovered some "swallowed" diagnostics in this class.
|
||||||
|
* We added a set of diagnostics (see property usages) to have additional protection before migrating to K2.
|
||||||
|
* For details see KT-55055, KT-55056, KT-55079.
|
||||||
|
* This property is normally true, but can be disabled with a feature NoAdditionalErrorsInK1DiagnosticReporter
|
||||||
|
*/
|
||||||
|
private val reportAdditionalErrors: Boolean
|
||||||
|
get() = !context.languageVersionSettings.supportsFeature(LanguageFeature.NoAdditionalErrorsInK1DiagnosticReporter)
|
||||||
|
|
||||||
override fun constraintError(error: ConstraintSystemError) {
|
override fun constraintError(error: ConstraintSystemError) {
|
||||||
when (error) {
|
when (error) {
|
||||||
is NewConstraintMismatch -> reportConstraintErrorByPosition(error, error.position.from)
|
is NewConstraintMismatch -> reportConstraintErrorByPosition(error, error.position.from)
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE: +NoAdditionalErrorsInK1DiagnosticReporter
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
buildList {
|
||||||
|
add("Boom")
|
||||||
|
println(plus(1)[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE: +NoAdditionalErrorsInK1DiagnosticReporter
|
||||||
|
// ISSUE: KT-55055
|
||||||
|
fun <T : Number> printGenericNumber(t: T) = println("Number is $t")
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
buildList { // inferred into MutableList<String>
|
||||||
|
add("Boom")
|
||||||
|
printGenericNumber(this[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+12
@@ -37604,6 +37604,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inconsistentTypeInference_noReporting.kt")
|
||||||
|
public void testInconsistentTypeInference_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("incorrectCalls.kt")
|
@TestMetadata("incorrectCalls.kt")
|
||||||
public void testIncorrectCalls() throws Exception {
|
public void testIncorrectCalls() throws Exception {
|
||||||
@@ -37676,6 +37682,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("upperBoundViolation_noReporting.kt")
|
||||||
|
public void testUpperBoundViolation_noReporting() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/upperBoundViolation_noReporting.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||||
|
|||||||
@@ -313,6 +313,13 @@ enum class LanguageFeature(
|
|||||||
// equality & identity operators in cases where K1 would report warnings or would not report anything.
|
// equality & identity operators in cases where K1 would report warnings or would not report anything.
|
||||||
ReportErrorsForComparisonOperators(sinceVersion = null, kind = BUG_FIX),
|
ReportErrorsForComparisonOperators(sinceVersion = null, kind = BUG_FIX),
|
||||||
|
|
||||||
|
// Disabled for indefinite time.
|
||||||
|
// Disables reporting of new errors (see KT-55055, KT-55056, KT-55079) in DiagnosticReporterByTrackingStrategy.
|
||||||
|
// All these errors are "lost" errors which existed always, but wasn't reported before 1.9.0.
|
||||||
|
// When this feature is disabled, all these "lost" errors are reported properly.
|
||||||
|
// When this feature is enabled, no such errors are reported.
|
||||||
|
NoAdditionalErrorsInK1DiagnosticReporter(sinceVersion = null, kind = OTHER),
|
||||||
|
|
||||||
// Experimental features
|
// Experimental features
|
||||||
|
|
||||||
BreakContinueInInlineLambdas(null), // KT-1436
|
BreakContinueInInlineLambdas(null), // KT-1436
|
||||||
|
|||||||
Reference in New Issue
Block a user