use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class DataFlowAnalyzer method typeHasOverriddenEquals.
private static boolean typeHasOverriddenEquals(@NotNull KotlinType type, @NotNull KtElement lookupElement) {
Collection<SimpleFunctionDescriptor> members = type.getMemberScope().getContributedFunctions(OperatorNameConventions.EQUALS, new KotlinLookupLocation(lookupElement));
for (FunctionDescriptor member : members) {
KotlinType returnType = member.getReturnType();
if (returnType == null || !KotlinBuiltIns.isBoolean(returnType))
continue;
if (member.getValueParameters().size() != 1)
continue;
KotlinType parameterType = member.getValueParameters().iterator().next().getType();
if (!KotlinBuiltIns.isNullableAny(parameterType))
continue;
FunctionDescriptor fromSuperClass = getOverriddenDescriptorFromClass(member);
if (fromSuperClass == null)
return false;
ClassifierDescriptor superClassDescriptor = (ClassifierDescriptor) fromSuperClass.getContainingDeclaration();
// We should have override fun in class other than Any (to prove unknown behaviour)
return !KotlinBuiltIns.isAnyOrNullableAny(superClassDescriptor.getDefaultType());
}
return false;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class DataFlowAnalyzer method recordExpectedType.
public void recordExpectedType(@NotNull BindingTrace trace, @NotNull KtExpression expression, @NotNull KotlinType expectedType) {
if (expectedType != NO_EXPECTED_TYPE) {
KotlinType normalizeExpectedType = expectedType == UNIT_EXPECTED_TYPE ? builtIns.getUnitType() : expectedType;
trace.record(BindingContext.EXPECTED_EXPRESSION_TYPE, expression, normalizeExpectedType);
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ExpressionTypingServices method getBodyExpressionType.
@NotNull
public KotlinType getBodyExpressionType(@NotNull BindingTrace trace, @NotNull LexicalScope outerScope, @NotNull DataFlowInfo dataFlowInfo, @NotNull KtDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor) {
KtExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
LexicalScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace, expressionTypingComponents.overloadChecker);
ExpressionTypingContext context = ExpressionTypingContext.newContext(trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE);
KotlinTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, function.hasBlockBody());
KotlinType type = typeInfo.getType();
if (type != null) {
return type;
} else {
return ErrorUtils.createErrorType("Error function type");
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class ControlFlowAnalyzer method process.
public void process(@NotNull BodiesResolveContext c) {
for (KtFile file : c.getFiles()) {
checkDeclarationContainer(c, file);
}
for (KtClassOrObject aClass : c.getDeclaredClasses().keySet()) {
checkDeclarationContainer(c, aClass);
}
for (KtScript script : c.getScripts().keySet()) {
checkDeclarationContainer(c, script);
}
for (KtSecondaryConstructor constructor : c.getSecondaryConstructors().keySet()) {
checkSecondaryConstructor(constructor);
}
for (Map.Entry<KtNamedFunction, SimpleFunctionDescriptor> entry : c.getFunctions().entrySet()) {
KtNamedFunction function = entry.getKey();
SimpleFunctionDescriptor functionDescriptor = entry.getValue();
KotlinType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType() ? NO_EXPECTED_TYPE : functionDescriptor.getReturnType();
checkFunction(c, function, expectedReturnType);
}
for (Map.Entry<KtProperty, PropertyDescriptor> entry : c.getProperties().entrySet()) {
KtProperty property = entry.getKey();
PropertyDescriptor propertyDescriptor = entry.getValue();
checkProperty(c, property, propertyDescriptor);
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class InlineCodegen method createMethodNode.
@NotNull
static SMAPAndMethodNode createMethodNode(@NotNull final FunctionDescriptor functionDescriptor, @NotNull JvmMethodSignature jvmSignature, @NotNull ExpressionCodegen codegen, @NotNull CodegenContext context, boolean callDefault, @Nullable ResolvedCall<?> resolvedCall) {
if (InlineCodegenUtil.isSpecialEnumMethod(functionDescriptor)) {
assert resolvedCall != null : "Resolved call for " + functionDescriptor + " should be not null";
Map<TypeParameterDescriptor, KotlinType> arguments = resolvedCall.getTypeArguments();
assert arguments.size() == 1 : "Resolved call for " + functionDescriptor + " should have 1 type argument";
MethodNode node = InlineCodegenUtil.createSpecialEnumMethodBody(codegen, functionDescriptor.getName().asString(), arguments.keySet().iterator().next().getDefaultType(), codegen.getState().getTypeMapper());
return new SMAPAndMethodNode(node, SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
} else if (CoroutineCodegenUtilKt.isBuiltInSuspendCoroutineOrReturnInJvm(functionDescriptor)) {
return new SMAPAndMethodNode(CoroutineCodegenUtilKt.createMethodNodeForSuspendCoroutineOrReturn(functionDescriptor, codegen.getState().getTypeMapper()), SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1));
}
final GenerationState state = codegen.getState();
final Method asmMethod = callDefault ? state.getTypeMapper().mapDefaultMethod(functionDescriptor, context.getContextKind()) : jvmSignature.getAsmMethod();
MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
final CallableMemberDescriptor directMember = getDirectMemberAndCallableFromObject(functionDescriptor);
if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
}
SMAPAndMethodNode resultInCache = InlineCacheKt.getOrPut(state.getInlineCache().getMethodNodeById(), methodId, new Function0<SMAPAndMethodNode>() {
@Override
public SMAPAndMethodNode invoke() {
SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
if (result == null) {
throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
}
return result;
}
});
return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
}
Aggregations