Report NON_VARARG_SPREAD on missed cases
^KT-48162 Fixed
This commit is contained in:
+6
@@ -31641,6 +31641,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48162.kt")
|
||||
public void testKt48162() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt48162.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("MoreSpecificVarargsOfEqualLength.kt")
|
||||
public void testMoreSpecificVarargsOfEqualLength() throws Exception {
|
||||
|
||||
+6
@@ -31689,6 +31689,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48162.kt")
|
||||
public void testKt48162() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt48162.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("MoreSpecificVarargsOfEqualLength.kt")
|
||||
public void testMoreSpecificVarargsOfEqualLength() throws Exception {
|
||||
|
||||
+6
@@ -31689,6 +31689,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48162.kt")
|
||||
public void testKt48162() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt48162.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("MoreSpecificVarargsOfEqualLength.kt")
|
||||
public void testMoreSpecificVarargsOfEqualLength() throws Exception {
|
||||
|
||||
@@ -755,7 +755,7 @@ public interface Errors {
|
||||
}
|
||||
|
||||
DiagnosticFactory0<KtExpression> VARARG_OUTSIDE_PARENTHESES = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<LeafPsiElement> NON_VARARG_SPREAD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactoryForDeprecation0<LeafPsiElement> NON_VARARG_SPREAD = DiagnosticFactoryForDeprecation0.create(LanguageFeature.ReportNonVarargSpreadOnGenericCalls);
|
||||
DiagnosticFactory0<LeafPsiElement> SPREAD_OF_NULLABLE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<LeafPsiElement> SPREAD_OF_LAMBDA_OR_CALLABLE_REFERENCE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
|
||||
+13
-3
@@ -280,9 +280,19 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
override fun onCallArgumentSpread(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
|
||||
when (diagnostic.javaClass) {
|
||||
NonVarargSpread::class.java -> {
|
||||
val spreadElement = callArgument.safeAs<ExpressionKotlinCallArgumentImpl>()?.valueArgument?.getSpreadElement()
|
||||
if (spreadElement != null) {
|
||||
trace.report(NON_VARARG_SPREAD.on(spreadElement))
|
||||
val castedPsiCallArgument = callArgument.safeAs<PSIKotlinCallArgument>()
|
||||
val castedCallArgument = callArgument.safeAs<ExpressionKotlinCallArgumentImpl>()
|
||||
|
||||
if (castedCallArgument != null) {
|
||||
val spreadElement = castedCallArgument.valueArgument.getSpreadElement()
|
||||
if (spreadElement != null) {
|
||||
trace.report(NON_VARARG_SPREAD.onError(spreadElement))
|
||||
}
|
||||
} else if (castedPsiCallArgument != null) {
|
||||
val spreadElement = castedPsiCallArgument.valueArgument.getSpreadElement()
|
||||
if (spreadElement != null) {
|
||||
trace.report(NON_VARARG_SPREAD.on(context.languageVersionSettings, spreadElement))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -349,7 +349,7 @@ public class ValueArgumentsToParametersMapper {
|
||||
else {
|
||||
LeafPsiElement spread = valueArgument.getSpreadElement();
|
||||
if (spread != null) {
|
||||
candidateCall.getTrace().report(NON_VARARG_SPREAD.on(spread));
|
||||
candidateCall.getTrace().report(NON_VARARG_SPREAD.onError(spread));
|
||||
setStatus(WEAK_ERROR);
|
||||
}
|
||||
ResolvedValueArgument argument = new ExpressionValueArgument(valueArgument);
|
||||
|
||||
@@ -9,10 +9,10 @@ fun main() {
|
||||
join(1)
|
||||
join(1, "2")
|
||||
join(1, "2", "3")
|
||||
join(<!NON_VARARG_SPREAD!>*<!>1, "2")
|
||||
join(<!NON_VARARG_SPREAD_ERROR!>*<!>1, "2")
|
||||
join(1, *<!TYPE_MISMATCH!>"2"<!>)
|
||||
join(x = 1, a = <!ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION_ERROR, TYPE_MISMATCH!>"2"<!>)
|
||||
join(x = <!NON_VARARG_SPREAD!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
join(x = <!NON_VARARG_SPREAD_ERROR!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
join(x = 1, a = a)
|
||||
join(x = 1, a = <!TYPE_MISMATCH!>b<!>)
|
||||
join(1, *a)
|
||||
@@ -29,11 +29,11 @@ fun main() {
|
||||
join(a = a, x = 1)
|
||||
|
||||
joinG<String>(1, "2")
|
||||
joinG<String>(<!NON_VARARG_SPREAD!>*<!>1, "2")
|
||||
joinG<String>(<!NON_VARARG_SPREAD_ERROR!>*<!>1, "2")
|
||||
joinG<String>(1, *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG<String>(x = 1, a = a)
|
||||
joinG<String>(x = 1, a = <!ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION_ERROR, TYPE_MISMATCH!>"2"<!>)
|
||||
joinG<String>(x = <!NON_VARARG_SPREAD!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG<String>(x = <!NON_VARARG_SPREAD_ERROR!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG<String>(1, *a)
|
||||
joinG<String>(1, *a, "3")
|
||||
joinG<String>(1, "4", *a, "3")
|
||||
@@ -42,11 +42,11 @@ fun main() {
|
||||
joinG<String>(a = a, x = 1)
|
||||
|
||||
joinG(1, "2")
|
||||
joinG(<!NON_VARARG_SPREAD!>*<!>1, "2")
|
||||
joinG(<!NON_VARARG_SPREAD_ERROR!>*<!>1, "2")
|
||||
joinG(1, *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG(x = 1, a = a)
|
||||
joinG(x = 1, a = <!ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION_ERROR, TYPE_MISMATCH!>"2"<!>)
|
||||
joinG(x = <!NON_VARARG_SPREAD!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG(x = <!NON_VARARG_SPREAD_ERROR!>*<!>1, a = *<!TYPE_MISMATCH!>"2"<!>)
|
||||
joinG(1, *a)
|
||||
joinG(1, *a, "3")
|
||||
joinG(1, "4", *a, "3")
|
||||
@@ -56,7 +56,7 @@ fun main() {
|
||||
|
||||
val x1 = joinT(1, "2")
|
||||
checkSubtype<String?>(x1)
|
||||
val x2 = joinT(<!NON_VARARG_SPREAD!>*<!>1, "2")
|
||||
val x2 = joinT(<!NON_VARARG_SPREAD_ERROR!>*<!>1, "2")
|
||||
checkSubtype<String?>(x2)
|
||||
val x6 = joinT(1, *a)
|
||||
checkSubtype<String?>(x6)
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ fun test6() {}
|
||||
|
||||
annotation class AnnArray(val a: Array<String>)
|
||||
|
||||
@AnnArray(*["/"])
|
||||
@AnnArray(<!NON_VARARG_SPREAD_WARNING!>*<!>["/"])
|
||||
fun testArray() {}
|
||||
|
||||
@Ann1(<!TYPE_MISMATCH, TYPE_MISMATCH!>[""]<!>)
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ fun getArr(): Array<String>? = null
|
||||
fun f() {
|
||||
A().foo(1, <!SPREAD_OF_NULLABLE!>*<!>args)
|
||||
bar(2, <!SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>args<!>)
|
||||
baz(<!NON_VARARG_SPREAD, SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>args<!>)
|
||||
baz(<!NON_VARARG_SPREAD_ERROR, SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>args<!>)
|
||||
}
|
||||
|
||||
fun g(args: Array<String>?) {
|
||||
@@ -55,7 +55,7 @@ fun h(b: B) {
|
||||
fun k() {
|
||||
A().foo(1, <!SPREAD_OF_NULLABLE!>*<!>getArr())
|
||||
bar(2, <!SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>getArr()<!>)
|
||||
baz(<!NON_VARARG_SPREAD, SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>getArr()<!>)
|
||||
baz(<!NON_VARARG_SPREAD_ERROR, SPREAD_OF_NULLABLE!>*<!><!TYPE_MISMATCH!>getArr()<!>)
|
||||
}
|
||||
|
||||
fun invokeTest(goodArgs: Array<String>) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
fun <T> Collection<T>.toArray(): Array<T> = this as Array<T>
|
||||
fun Collection<String>.toArray2(): Array<String> = this as Array<String>
|
||||
fun <T> toArray3(x: Collection<T>): Array<T> = x as Array<T>
|
||||
|
||||
class Foo<T> {
|
||||
operator fun plus(x: Foo<T>): Array<T> {
|
||||
return this + x
|
||||
}
|
||||
}
|
||||
|
||||
fun use(arg: Array<String>, s: Collection<String>, x: Foo<String>) {
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>arg)
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>s.toArray())
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>s.toArray2())
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>toArray3(s))
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>x + x)
|
||||
arr(<!NON_VARARG_SPREAD!>*<!>(x + x))
|
||||
}
|
||||
|
||||
fun arr(x: Array<String>) {}
|
||||
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
fun <T> Collection<T>.toArray(): Array<T> = this as Array<T>
|
||||
fun Collection<String>.toArray2(): Array<String> = this as Array<String>
|
||||
fun <T> toArray3(x: Collection<T>): Array<T> = x as Array<T>
|
||||
|
||||
class Foo<T> {
|
||||
operator fun plus(x: Foo<T>): Array<T> {
|
||||
return this + x
|
||||
}
|
||||
}
|
||||
|
||||
fun use(arg: Array<String>, s: Collection<String>, x: Foo<String>) {
|
||||
arr(<!NON_VARARG_SPREAD_ERROR!>*<!>arg)
|
||||
arr(<!NON_VARARG_SPREAD_WARNING!>*<!>s.toArray())
|
||||
arr(<!NON_VARARG_SPREAD_ERROR!>*<!>s.toArray2())
|
||||
arr(<!NON_VARARG_SPREAD_WARNING!>*<!>toArray3(s))
|
||||
arr(<!NON_VARARG_SPREAD_ERROR!>*<!>x + x)
|
||||
arr(<!NON_VARARG_SPREAD_ERROR!>*<!>(x + x))
|
||||
}
|
||||
|
||||
fun arr(x: Array<String>) {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public fun arr(/*0*/ x: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
public fun </*0*/ T> toArray3(/*0*/ x: kotlin.collections.Collection<T>): kotlin.Array<T>
|
||||
public fun use(/*0*/ arg: kotlin.Array<kotlin.String>, /*1*/ s: kotlin.collections.Collection<kotlin.String>, /*2*/ x: Foo<kotlin.String>): kotlin.Unit
|
||||
public fun </*0*/ T> kotlin.collections.Collection<T>.toArray(): kotlin.Array<T>
|
||||
public fun kotlin.collections.Collection<kotlin.String>.toArray2(): kotlin.Array<kotlin.String>
|
||||
|
||||
public final class Foo</*0*/ T> {
|
||||
public constructor Foo</*0*/ T>()
|
||||
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 final operator fun plus(/*0*/ x: Foo<T>): kotlin.Array<T>
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
Generated
+6
@@ -31785,6 +31785,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48162.kt")
|
||||
public void testKt48162() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/varargs/kt48162.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("MoreSpecificVarargsOfEqualLength.kt")
|
||||
public void testMoreSpecificVarargsOfEqualLength() throws Exception {
|
||||
|
||||
@@ -227,6 +227,7 @@ enum class LanguageFeature(
|
||||
ProhibitInvalidCharsInNativeIdentifiers(KOTLIN_1_7, kind = BUG_FIX),
|
||||
DefinitelyNotNullTypeParameters(KOTLIN_1_7),
|
||||
DefinitelyNonNullableTypes(KOTLIN_1_7),
|
||||
ReportNonVarargSpreadOnGenericCalls(KOTLIN_1_7, kind = BUG_FIX),
|
||||
ProhibitSimplificationOfNonTrivialConstBooleanExpressions(KOTLIN_1_7),
|
||||
SafeCallsAreAlwaysNullable(KOTLIN_1_7),
|
||||
StopPropagatingDeprecationThroughOverrides(KOTLIN_1_7),
|
||||
|
||||
Reference in New Issue
Block a user