use of org.jetbrains.kotlin.psi.KtTypeProjection in project kotlin by JetBrains.
the class ReifiedTypeParameterSubstitutionChecker method check.
@Override
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
for (Map.Entry<TypeParameterDescriptor, KotlinType> entry : typeArguments.entrySet()) {
TypeParameterDescriptor parameter = entry.getKey();
KotlinType argument = entry.getValue();
ClassifierDescriptor argumentDeclarationDescriptor = argument.getConstructor().getDeclarationDescriptor();
if (!parameter.isReified() && !isTypeParameterOfKotlinArray(parameter)) {
continue;
}
KtTypeProjection typeProjection = CollectionsKt.getOrNull(resolvedCall.getCall().getTypeArguments(), parameter.getIndex());
PsiElement reportErrorOn = typeProjection != null ? typeProjection : reportOn;
if (argumentDeclarationDescriptor instanceof TypeParameterDescriptor && !((TypeParameterDescriptor) argumentDeclarationDescriptor).isReified()) {
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));
}
// REIFIED_TYPE_UNSAFE_SUBSTITUTION is temporary disabled because it seems too strict now (see KT-10847)
//else if (TypeUtilsKt.unsafeAsReifiedArgument(argument) && !hasPureReifiableAnnotation(parameter)) {
// context.getTrace().report(Errors.REIFIED_TYPE_UNSAFE_SUBSTITUTION.on(reportErrorOn, argument));
//}
}
}
use of org.jetbrains.kotlin.psi.KtTypeProjection in project kotlin by JetBrains.
the class TypeUnifierTest method makeType.
private TypeProjection makeType(String typeStr) {
LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, module, false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
handler.addClassifierDescriptor(x);
handler.addClassifierDescriptor(y);
return Unit.INSTANCE;
}
});
KtTypeProjection projection = KtPsiFactoryKt.KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
KtTypeReference typeReference = projection.getTypeReference();
assert typeReference != null;
KotlinType type = typeResolver.resolveType(withX, typeReference, KotlinTestUtils.DUMMY_TRACE, true);
return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type);
}
Aggregations