Check implicitly inferred Nothing inside special calls properly: compare constructors instead of types
^KT-41176 Open
This commit is contained in:
+5
@@ -24220,6 +24220,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt")
|
||||
public void testImplicitNothingOfJavaCallAgainstNotNothingExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOnDelegates.kt")
|
||||
public void testImplicitNothingOnDelegates() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.kt");
|
||||
|
||||
+3
-1
@@ -97,7 +97,9 @@ object ImplicitNothingAsTypeParameterCallChecker : CallChecker {
|
||||
|
||||
val resolvedCallAtom = resolvedAtom.getResolvedCallAtom(context.trace.bindingContext) ?: continue
|
||||
val candidateDescriptor = resolvedCallAtom.candidateDescriptor
|
||||
val isReturnTypeOwnTypeParameter = candidateDescriptor.typeParameters.any { it.defaultType == candidateDescriptor.returnType }
|
||||
val isReturnTypeOwnTypeParameter = candidateDescriptor.typeParameters.any {
|
||||
it.typeConstructor == candidateDescriptor.returnType?.constructor
|
||||
}
|
||||
val isSpecialCall = candidateDescriptor.name in SPECIAL_FUNCTION_NAMES
|
||||
val hasExplicitTypeArguments = resolvedCallAtom.atom.psiKotlinCall.typeArguments.isNotEmpty() // not required
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
|
||||
// FILE: abc/Bar.java
|
||||
|
||||
package abc;
|
||||
|
||||
public class Bar {
|
||||
public static <T> T bar() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import abc.Bar
|
||||
|
||||
fun ifProblem(b: Boolean): String? {
|
||||
return run {
|
||||
if (b) { Bar.bar() } else null
|
||||
}
|
||||
}
|
||||
|
||||
fun whenProblem(b: Boolean): String? {
|
||||
return run {
|
||||
when {
|
||||
b -> Bar.bar()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun tryProblem(): String? {
|
||||
return run {
|
||||
try {
|
||||
Bar.bar()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNCHECKED_CAST -UNUSED_EXPRESSION -UNREACHABLE_CODE
|
||||
|
||||
// FILE: abc/Bar.java
|
||||
|
||||
package abc;
|
||||
|
||||
public class Bar {
|
||||
public static <T> T bar() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import abc.Bar
|
||||
|
||||
fun ifProblem(b: Boolean): String? {
|
||||
return run {
|
||||
if (b) { Bar.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_AGAINST_NOT_NOTHING_EXPECTED_TYPE!>bar<!>() } else null
|
||||
}
|
||||
}
|
||||
|
||||
fun whenProblem(b: Boolean): String? {
|
||||
return run {
|
||||
when {
|
||||
b -> Bar.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_AGAINST_NOT_NOTHING_EXPECTED_TYPE!>bar<!>()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun tryProblem(): String? {
|
||||
return run {
|
||||
try {
|
||||
Bar.<!IMPLICIT_NOTHING_TYPE_ARGUMENT_AGAINST_NOT_NOTHING_EXPECTED_TYPE!>bar<!>()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
public fun ifProblem(/*0*/ b: kotlin.Boolean): kotlin.String?
|
||||
public fun tryProblem(): kotlin.String?
|
||||
public fun whenProblem(/*0*/ b: kotlin.Boolean): kotlin.String?
|
||||
|
||||
package abc {
|
||||
|
||||
public open class Bar {
|
||||
public constructor Bar()
|
||||
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
|
||||
|
||||
// Static members
|
||||
public open fun </*0*/ T : kotlin.Any!> bar(): T!
|
||||
}
|
||||
}
|
||||
@@ -24302,6 +24302,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt")
|
||||
public void testImplicitNothingOfJavaCallAgainstNotNothingExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOnDelegates.kt")
|
||||
public void testImplicitNothingOnDelegates() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.kt");
|
||||
|
||||
Generated
+5
@@ -24222,6 +24222,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt")
|
||||
public void testImplicitNothingOfJavaCallAgainstNotNothingExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOfJavaCallAgainstNotNothingExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitNothingOnDelegates.kt")
|
||||
public void testImplicitNothingOnDelegates() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.kt");
|
||||
|
||||
Reference in New Issue
Block a user