Correct diagnostics and quick-fix for T::class with non-reified type parameter #KT-9590 fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
998399bcd8
commit
2b63bcaa19
+1
-1
@@ -50,7 +50,7 @@ public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||
|
||||
if (argumentDeclarationDescriptor instanceof TypeParameterDescriptor &&
|
||||
!((TypeParameterDescriptor) argumentDeclarationDescriptor).isReified()) {
|
||||
context.getTrace().report(Errors.TYPE_PARAMETER_AS_REIFIED.on(reportErrorOn, parameter));
|
||||
context.getTrace().report(Errors.TYPE_PARAMETER_AS_REIFIED.on(reportErrorOn, (TypeParameterDescriptor) argumentDeclarationDescriptor));
|
||||
}
|
||||
else if (TypeUtilsKt.cannotBeReified(argument)) {
|
||||
context.getTrace().report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(reportErrorOn, argument));
|
||||
|
||||
+9
-5
@@ -48,12 +48,11 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
import java.lang.UnsupportedOperationException
|
||||
import javax.inject.Inject
|
||||
|
||||
sealed class DoubleColonLHS(val type: KotlinType) {
|
||||
@@ -119,7 +118,12 @@ class DoubleColonExpressionResolver(
|
||||
reportError = !isAllowedInClassLiteral(type)
|
||||
}
|
||||
|
||||
if (type.isMarkedNullable || reportError) {
|
||||
|
||||
val typeParameterDescriptor = TypeUtils.getTypeParameterDescriptorOrNull(type)
|
||||
if (type is SimpleType && !type.isMarkedNullable && typeParameterDescriptor != null && !typeParameterDescriptor.isReified) {
|
||||
c.trace.report(TYPE_PARAMETER_AS_REIFIED.on(expression, typeParameterDescriptor))
|
||||
}
|
||||
else if (type.isMarkedNullable || reportError) {
|
||||
c.trace.report(CLASS_LITERAL_LHS_NOT_A_CLASS.on(expression))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ val l1 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>List<String>?::class<!>
|
||||
val l2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>List?::class<!>
|
||||
|
||||
fun <T : Any> foo() {
|
||||
val t1 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>T::class<!>
|
||||
val t1 = <!TYPE_PARAMETER_AS_REIFIED!>T::class<!>
|
||||
val t2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>T?::class<!>
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
fun <T: Any> dereferenceClass(): Any =
|
||||
<!TYPE_PARAMETER_AS_REIFIED!>T::class<!>
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T : kotlin.Any> dereferenceClass(): kotlin.Any
|
||||
@@ -8339,6 +8339,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassDereference.kt")
|
||||
public void testClassDereference() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/tpAsReified/ClassDereference.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Conventions.kt")
|
||||
public void testConventions() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/tpAsReified/Conventions.kt");
|
||||
|
||||
Reference in New Issue
Block a user