K1: don't report assignment TYPE_MISMATCH in BI under feature ON
Related to KT-54004
This commit is contained in:
committed by
Space Team
parent
6c6d653e85
commit
8e48636b29
+12
@@ -35858,6 +35858,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignmentExtra.kt")
|
||||
public void testUnsafeAssignmentExtra() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignment_noReport.kt")
|
||||
public void testUnsafeAssignment_noReport() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment_noReport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||
|
||||
+12
@@ -35858,6 +35858,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignmentExtra.kt")
|
||||
public void testUnsafeAssignmentExtra() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignment_noReport.kt")
|
||||
public void testUnsafeAssignment_noReport() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment_noReport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||
|
||||
+12
@@ -35858,6 +35858,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignmentExtra.kt")
|
||||
public void testUnsafeAssignmentExtra() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignment_noReport.kt")
|
||||
public void testUnsafeAssignment_noReport() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment_noReport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||
|
||||
+2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
@@ -28,6 +29,7 @@ object BuilderInferenceAssignmentChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (resultingDescriptor !is PropertyDescriptor) return
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.NoBuilderInferenceWithoutAnnotationRestriction)) return
|
||||
if (resolvedCall.candidateDescriptor.returnType !is StubTypeForBuilderInference) return
|
||||
if (reportOn !is KtNameReferenceExpression) return
|
||||
val binaryExpression = reportOn.getParentOfType<KtBinaryExpression>(strict = true) ?: return
|
||||
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
// WITH_REFLECT
|
||||
import kotlin.reflect.*
|
||||
|
||||
interface Foo<T : Any> {
|
||||
var a: T
|
||||
val b: Array<T>
|
||||
|
||||
fun accept(arg: T)
|
||||
}
|
||||
|
||||
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class FooImpl<!><T : Any> : Foo<T>
|
||||
|
||||
fun bar(p: KMutableProperty0<Int>) {
|
||||
p.set(100)
|
||||
}
|
||||
|
||||
fun <T : Any> myBuilder(block: Foo<T>.() -> Unit): Foo<T> = FooImpl<T>().apply(block)
|
||||
|
||||
fun <T : Any> Foo<T>.change(block: Foo<T>.() -> Unit): Foo<T> {
|
||||
this.block()
|
||||
return this
|
||||
}
|
||||
|
||||
fun main(arg: Any, condition: Boolean) {
|
||||
val value = myBuilder {
|
||||
b[0] = 123
|
||||
a = 45
|
||||
a<!OVERLOAD_RESOLUTION_AMBIGUITY!>++<!>
|
||||
bar(::a)
|
||||
if (<!USELESS_IS_CHECK!>a is Int<!>) {
|
||||
a = 67
|
||||
a<!OVERLOAD_RESOLUTION_AMBIGUITY!>--<!>
|
||||
bar(::a)
|
||||
}
|
||||
when (condition) {
|
||||
true -> a = 87
|
||||
false -> a = 65
|
||||
}
|
||||
val x by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY!>a<!>
|
||||
|
||||
change {
|
||||
a = 99
|
||||
}
|
||||
}
|
||||
|
||||
val value2 = myBuilder {
|
||||
accept("")
|
||||
a = <!ASSIGNMENT_TYPE_MISMATCH!>45<!>
|
||||
when (condition) {
|
||||
true -> a = <!ASSIGNMENT_TYPE_MISMATCH!>87<!>
|
||||
false -> a = <!ASSIGNMENT_TYPE_MISMATCH!>65<!>
|
||||
}
|
||||
change {
|
||||
a = <!ASSIGNMENT_TYPE_MISMATCH!>99<!>
|
||||
}
|
||||
if (a is Int) {
|
||||
a = <!ASSIGNMENT_TYPE_MISMATCH!>67<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// WITH_REFLECT
|
||||
import kotlin.reflect.*
|
||||
|
||||
interface Foo<T : Any> {
|
||||
var a: T
|
||||
val b: Array<T>
|
||||
|
||||
fun accept(arg: T)
|
||||
}
|
||||
|
||||
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class FooImpl<!><T : Any> : Foo<T>
|
||||
|
||||
fun bar(p: KMutableProperty0<Int>) {
|
||||
p.set(100)
|
||||
}
|
||||
|
||||
fun <T : Any> myBuilder(block: Foo<T>.() -> Unit): Foo<T> = FooImpl<T>().apply(block)
|
||||
|
||||
fun <T : Any> Foo<T>.change(block: Foo<T>.() -> Unit): Foo<T> {
|
||||
this.block()
|
||||
return this
|
||||
}
|
||||
|
||||
fun main(arg: Any, condition: Boolean) {
|
||||
val value = myBuilder {
|
||||
b[0] = 123
|
||||
a = 45
|
||||
<!STUB_TYPE_IN_RECEIVER_CAUSES_AMBIGUITY!>a<!><!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, OVERLOAD_RESOLUTION_AMBIGUITY, OVERLOAD_RESOLUTION_AMBIGUITY_BECAUSE_OF_STUB_TYPES!>++<!>
|
||||
bar(::a)
|
||||
if (<!USELESS_IS_CHECK, USELESS_IS_CHECK!>a is Int<!>) {
|
||||
a = 67
|
||||
<!STUB_TYPE_IN_RECEIVER_CAUSES_AMBIGUITY!>a<!><!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, OVERLOAD_RESOLUTION_AMBIGUITY, OVERLOAD_RESOLUTION_AMBIGUITY_BECAUSE_OF_STUB_TYPES!>--<!>
|
||||
bar(::a)
|
||||
}
|
||||
when (condition) {
|
||||
true -> a = 87
|
||||
false -> a = 65
|
||||
}
|
||||
val x by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY!>a<!>
|
||||
|
||||
change {
|
||||
a = 99
|
||||
}
|
||||
}
|
||||
|
||||
val value2 = myBuilder {
|
||||
accept("")
|
||||
a = <!TYPE_MISMATCH!>45<!>
|
||||
when (condition) {
|
||||
true -> a = <!TYPE_MISMATCH!>87<!>
|
||||
false -> a = <!TYPE_MISMATCH!>65<!>
|
||||
}
|
||||
change {
|
||||
a = <!TYPE_MISMATCH!>99<!>
|
||||
}
|
||||
if (<!USELESS_IS_CHECK, USELESS_IS_CHECK!>a is Int<!>) {
|
||||
a = <!TYPE_MISMATCH!>67<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ p: kotlin.reflect.KMutableProperty0<kotlin.Int>): kotlin.Unit
|
||||
public fun main(/*0*/ arg: kotlin.Any, /*1*/ condition: kotlin.Boolean): kotlin.Unit
|
||||
public fun </*0*/ T : kotlin.Any> myBuilder(/*0*/ block: Foo<T>.() -> kotlin.Unit): Foo<T>
|
||||
public fun </*0*/ T : kotlin.Any> Foo<T>.change(/*0*/ block: Foo<T>.() -> kotlin.Unit): Foo<T>
|
||||
|
||||
public interface Foo</*0*/ T : kotlin.Any> {
|
||||
public abstract var a: T
|
||||
public abstract val b: kotlin.Array<T>
|
||||
public abstract fun accept(/*0*/ arg: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class FooImpl</*0*/ T : kotlin.Any> : Foo<T> {
|
||||
public constructor FooImpl</*0*/ T : kotlin.Any>()
|
||||
public abstract override /*1*/ /*fake_override*/ var a: T
|
||||
public abstract override /*1*/ /*fake_override*/ val b: kotlin.Array<T>
|
||||
public abstract override /*1*/ /*fake_override*/ fun accept(/*0*/ arg: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +NoBuilderInferenceWithoutAnnotationRestriction
|
||||
|
||||
class Foo<T : Any> {
|
||||
fun doSmthng(arg: T) {}
|
||||
var a: T? = null
|
||||
}
|
||||
|
||||
fun <T : Any> myBuilder(block: Foo<T>.() -> Unit) : Foo<T> = Foo<T>().apply(block)
|
||||
|
||||
fun main(arg: Any) {
|
||||
val x = 57
|
||||
val value = myBuilder {
|
||||
doSmthng("one ")
|
||||
a = <!ASSIGNMENT_TYPE_MISMATCH!>57<!>
|
||||
a = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
if (arg is String) {
|
||||
a = arg
|
||||
}
|
||||
}
|
||||
println(value.a?.count { it in 'l' .. 'q' })
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +NoBuilderInferenceWithoutAnnotationRestriction
|
||||
|
||||
class Foo<T : Any> {
|
||||
fun doSmthng(arg: T) {}
|
||||
var a: T? = null
|
||||
}
|
||||
|
||||
fun <T : Any> myBuilder(block: Foo<T>.() -> Unit) : Foo<T> = Foo<T>().apply(block)
|
||||
|
||||
fun main(arg: Any) {
|
||||
val x = 57
|
||||
val value = myBuilder {
|
||||
doSmthng("one ")
|
||||
a = 57
|
||||
a = x
|
||||
if (arg is String) {
|
||||
a = arg
|
||||
}
|
||||
}
|
||||
println(value.a?.count { it in 'l' .. 'q' })
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun main(/*0*/ arg: kotlin.Any): kotlin.Unit
|
||||
public fun </*0*/ T : kotlin.Any> myBuilder(/*0*/ block: Foo<T>.() -> kotlin.Unit): Foo<T>
|
||||
|
||||
public final class Foo</*0*/ T : kotlin.Any> {
|
||||
public constructor Foo</*0*/ T : kotlin.Any>()
|
||||
public final var a: T?
|
||||
public final fun doSmthng(/*0*/ arg: T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+12
@@ -35948,6 +35948,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignmentExtra.kt")
|
||||
public void testUnsafeAssignmentExtra() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unsafeAssignment_noReport.kt")
|
||||
public void testUnsafeAssignment_noReport() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignment_noReport.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("useInferenceInformationFromExtension.kt")
|
||||
public void testUseInferenceInformationFromExtension() throws Exception {
|
||||
|
||||
@@ -295,6 +295,10 @@ enum class LanguageFeature(
|
||||
ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null),
|
||||
|
||||
// Disabled for indefinite time. Disables restrictions of builder inference without annotation
|
||||
// Note: In 1.7.0, builder inference without annotation was introduced.
|
||||
// However, later we encountered various situations when it works incorrectly, and decided to forbid them.
|
||||
// When this feature is disabled, various errors are reported which are related to these incorrect situations.
|
||||
// When this feature is enabled, no such errors are reported.
|
||||
NoBuilderInferenceWithoutAnnotationRestriction(sinceVersion = null, kind = OTHER, defaultState = State.DISABLED),
|
||||
|
||||
// Experimental features
|
||||
|
||||
Reference in New Issue
Block a user