use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ExpressionTypingVisitorForStatements method visitAssignment.
@NotNull
protected KotlinTypeInfo visitAssignment(KtBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceScope(scope).replaceContextDependency(INDEPENDENT);
KtExpression leftOperand = expression.getLeft();
if (leftOperand instanceof KtAnnotatedExpression) {
basic.resolveAnnotationsOnExpression((KtAnnotatedExpression) leftOperand, context);
}
KtExpression left = deparenthesize(leftOperand);
KtExpression right = expression.getRight();
if (left instanceof KtArrayAccessExpression) {
KtArrayAccessExpression arrayAccessExpression = (KtArrayAccessExpression) left;
if (right == null)
return TypeInfoFactoryKt.noTypeInfo(context);
KotlinTypeInfo typeInfo = basic.resolveArrayAccessSetMethod(arrayAccessExpression, right, context, context.trace);
basic.checkLValue(context.trace, context, arrayAccessExpression, right, expression);
return typeInfo.replaceType(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType));
}
KotlinTypeInfo leftInfo = ExpressionTypingUtils.getTypeInfoOrNullType(left, context, facade);
KotlinType expectedType = refineTypeFromPropertySetterIfPossible(context.trace.getBindingContext(), leftOperand, leftInfo.getType());
DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo();
KotlinTypeInfo resultInfo;
if (right != null) {
resultInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo).replaceExpectedType(expectedType).replaceCallPosition(new CallPosition.PropertyAssignment(leftOperand)));
dataFlowInfo = resultInfo.getDataFlowInfo();
KotlinType rightType = resultInfo.getType();
if (left != null && expectedType != null && rightType != null) {
DataFlowValue leftValue = DataFlowValueFactory.createDataFlowValue(left, expectedType, context);
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rightType, context);
// We cannot say here anything new about rightValue except it has the same value as leftValue
resultInfo = resultInfo.replaceDataFlowInfo(dataFlowInfo.assign(leftValue, rightValue, components.languageVersionSettings));
}
} else {
resultInfo = leftInfo;
}
if (expectedType != null && leftOperand != null) {
//if expectedType == null, some other error has been generated
basic.checkLValue(context.trace, context, leftOperand, right, expression);
}
return resultInfo.replaceType(components.dataFlowAnalyzer.checkStatementType(expression, contextWithExpectedType));
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ForLoopConventionsChecker method checkIterableConvention.
@Nullable
public KotlinType checkIterableConvention(@NotNull ExpressionReceiver loopRange, @NotNull ExpressionTypingContext context) {
KtExpression loopRangeExpression = loopRange.getExpression();
// Make a fake call loopRange.iterator(), and try to resolve it
OverloadResolutionResults<FunctionDescriptor> iteratorResolutionResults = fakeCallResolver.resolveFakeCall(context, loopRange, OperatorNameConventions.ITERATOR, loopRangeExpression, loopRangeExpression, FakeCallKind.ITERATOR, Collections.<KtExpression>emptyList());
if (!iteratorResolutionResults.isSuccess())
return null;
ResolvedCall<FunctionDescriptor> iteratorResolvedCall = iteratorResolutionResults.getResultingCall();
context.trace.record(LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRangeExpression, iteratorResolvedCall);
FunctionDescriptor iteratorFunction = iteratorResolvedCall.getResultingDescriptor();
checkIfOperatorModifierPresent(loopRangeExpression, iteratorFunction, context.trace);
KotlinType iteratorType = iteratorFunction.getReturnType();
//noinspection ConstantConditions
KotlinType hasNextType = checkConventionForIterator(context, loopRangeExpression, iteratorType, OperatorNameConventions.HAS_NEXT, HAS_NEXT_FUNCTION_AMBIGUITY, HAS_NEXT_MISSING, HAS_NEXT_FUNCTION_NONE_APPLICABLE, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL);
if (hasNextType != null && !builtIns.isBooleanOrSubtype(hasNextType)) {
context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRangeExpression, hasNextType));
}
return checkConventionForIterator(context, loopRangeExpression, iteratorType, OperatorNameConventions.NEXT, NEXT_AMBIGUITY, NEXT_MISSING, NEXT_NONE_APPLICABLE, LOOP_RANGE_NEXT_RESOLVED_CALL);
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class AnnotationResolverImpl method resolveAnnotationType.
@Override
@NotNull
public KotlinType resolveAnnotationType(@NotNull LexicalScope scope, @NotNull KtAnnotationEntry entryElement, @NotNull BindingTrace trace) {
KtTypeReference typeReference = entryElement.getTypeReference();
if (typeReference == null) {
return ErrorUtils.createErrorType("No type reference: " + entryElement.getText());
}
KotlinType type = typeResolver.resolveType(scope, typeReference, trace, true);
if (!(type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
return ErrorUtils.createErrorType("Not an annotation: " + type);
}
return type;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class CompileTimeConstantUtils method checkConstructorParametersType.
public static void checkConstructorParametersType(@NotNull List<KtParameter> parameters, @NotNull BindingTrace trace) {
for (KtParameter parameter : parameters) {
VariableDescriptor parameterDescriptor = trace.getBindingContext().get(VALUE_PARAMETER, parameter);
if (parameterDescriptor == null)
continue;
KotlinType parameterType = parameterDescriptor.getType();
KtTypeReference typeReference = parameter.getTypeReference();
if (typeReference != null) {
if (parameterType.isMarkedNullable()) {
trace.report(NULLABLE_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
} else if (!isAcceptableTypeForAnnotationParameter(parameterType)) {
trace.report(INVALID_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
}
}
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ControlFlowAnalyzer method checkProperty.
private void checkProperty(@NotNull BodiesResolveContext c, KtProperty property, PropertyDescriptor propertyDescriptor) {
for (KtPropertyAccessor accessor : property.getAccessors()) {
PropertyAccessorDescriptor accessorDescriptor = accessor.isGetter() ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
assert accessorDescriptor != null : "no property accessor descriptor " + accessor.getText();
KotlinType returnType = accessorDescriptor.getReturnType();
checkFunction(c, accessor, returnType);
}
}
Aggregations