Prohibit using definitely-non-nullable types as arguments for reified parameters
^KT-26245 In Progress
This commit is contained in:
committed by
teamcityserver
parent
62bef48f9d
commit
0e7d51b04d
+6
@@ -10115,6 +10115,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reifiedArguments.kt")
|
||||
public void testReifiedArguments() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/reifiedArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
|
||||
+6
@@ -10115,6 +10115,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reifiedArguments.kt")
|
||||
public void testReifiedArguments() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/reifiedArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
|
||||
@@ -788,6 +788,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends CallableDescriptor>> CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> DEFINITELY_NON_NULLABLE_AS_REIFIED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactoryForDeprecation1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED_ARRAY = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitNonReifiedArraysAsReifiedTypeArguments);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> REIFIED_TYPE_UNSAFE_SUBSTITUTION = DiagnosticFactory1.create(WARNING);
|
||||
|
||||
+1
@@ -941,6 +941,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPE_ARGUMENTS_NOT_ALLOWED, "Type arguments are not allowed {0}", STRING);
|
||||
|
||||
MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME);
|
||||
MAP.put(DEFINITELY_NON_NULLABLE_AS_REIFIED, "Cannot use definitely-non-nullable type as reified type argument");
|
||||
MAP.put(TYPE_PARAMETER_AS_REIFIED_ARRAY, "Cannot use ''{0}'' as reified type parameter, since the array type parameter is not reified.", NAME);
|
||||
MAP.put(REIFIED_TYPE_PARAMETER_NO_INLINE, "Only type parameters of inline functions can be reified");
|
||||
MAP.put(REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, "Cannot use ''{0}'' as reified type parameter", RENDER_TYPE);
|
||||
|
||||
+5
-1
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
@@ -30,6 +29,7 @@ import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.model.DefinitelyNotNullTypeMarker;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -50,6 +50,10 @@ public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||
KtTypeProjection typeProjection = CollectionsKt.getOrNull(resolvedCall.getCall().getTypeArguments(), parameter.getIndex());
|
||||
|
||||
checkTypeArgument(typeProjection != null ? typeProjection : reportOn, context, argument, argumentDeclarationDescriptor, false);
|
||||
|
||||
if (typeProjection != null && argument instanceof DefinitelyNotNullTypeMarker) {
|
||||
context.getTrace().report(Errors.DEFINITELY_NON_NULLABLE_AS_REIFIED.on(typeProjection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||
|
||||
inline fun <reified T : Any> foo() {}
|
||||
|
||||
inline fun <reified F> bar() {
|
||||
foo<F & Any>()
|
||||
}
|
||||
compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/reifiedArguments.kt
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||
|
||||
inline fun <reified T : Any> foo() {}
|
||||
|
||||
inline fun <reified F> bar() {
|
||||
foo<<!DEFINITELY_NON_NULLABLE_AS_REIFIED!>F & Any<!>>()
|
||||
}
|
||||
Generated
+6
@@ -10121,6 +10121,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reifiedArguments.kt")
|
||||
public void testReifiedArguments() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/reifiedArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
|
||||
+6
@@ -10115,6 +10115,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reifiedArguments.kt")
|
||||
public void testReifiedArguments() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/reifiedArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user