Fixes for KT-4991: Prefix/postfix expressions resolved to local extensions are not supported in codegen;
KT-4989: Verify error on local functions and extensions; KT-4987: NegativeArraySizeException on local extension convention function on nullable Int #KT-4991 Fixed #KT-4989 Fixed #KT-4987 Fixed
This commit is contained in:
@@ -3069,24 +3069,25 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitPrefixExpression(@NotNull JetPrefixExpression expression, StackValue receiver) {
|
||||
DeclarationDescriptor op = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
||||
DeclarationDescriptor originalOperation = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
CallableDescriptor op = resolvedCall.getResultingDescriptor();
|
||||
|
||||
assert op instanceof FunctionDescriptor || originalOperation == null : String.valueOf(op);
|
||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||
if (callable instanceof IntrinsicMethod) {
|
||||
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
||||
Type returnType = typeMapper.mapType(op);
|
||||
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
||||
Collections.singletonList(expression.getBaseExpression()), receiver);
|
||||
return StackValue.onStack(returnType);
|
||||
}
|
||||
|
||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
|
||||
if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
|
||||
if (isPrimitiveNumberClassDescriptor(cls) || !(originalOperation.getName().asString().equals("inc") || originalOperation.getName().asString().equals("dec"))) {
|
||||
return invokeFunction(resolvedCall, receiver);
|
||||
}
|
||||
|
||||
CallableMethod callableMethod = (CallableMethod) callable;
|
||||
|
||||
StackValue value = gen(expression.getBaseExpression());
|
||||
value.dupReceiver(v);
|
||||
@@ -3096,6 +3097,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
value.put(type, v);
|
||||
invokeFunction(resolvedCall, StackValue.onStack(type));
|
||||
|
||||
CallableMethod callableMethod = (CallableMethod) callable;
|
||||
value.store(callableMethod.getReturnType(), v);
|
||||
value.put(type, v);
|
||||
return StackValue.onStack(type);
|
||||
@@ -3117,23 +3119,26 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return StackValue.onStack(base.type);
|
||||
}
|
||||
|
||||
DeclarationDescriptor op = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||
if (!(op instanceof FunctionDescriptor)) {
|
||||
throw new UnsupportedOperationException("Don't know how to generate this postfix expression: " + op);
|
||||
DeclarationDescriptor originalOperation = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||
String originalOperationName = originalOperation != null ? originalOperation.getName().asString() : null;
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
DeclarationDescriptor op = resolvedCall.getResultingDescriptor();
|
||||
if (!(op instanceof FunctionDescriptor) || originalOperation == null) {
|
||||
throw new UnsupportedOperationException("Don't know how to generate this postfix expression: " + originalOperationName + " " + op);
|
||||
}
|
||||
|
||||
Type asmType = expressionType(expression);
|
||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||
|
||||
int increment;
|
||||
if (op.getName().asString().equals("inc")) {
|
||||
if (originalOperationName.equals("inc")) {
|
||||
increment = 1;
|
||||
}
|
||||
else if (op.getName().asString().equals("dec")) {
|
||||
else if (originalOperationName.equals("dec")) {
|
||||
increment = -1;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unsupported postfix operation: " + op);
|
||||
throw new UnsupportedOperationException("Unsupported postfix operation: " + originalOperationName + " " + op);
|
||||
}
|
||||
|
||||
boolean isPrimitiveNumberClassDescriptor = isPrimitiveNumberClassDescriptor(cls);
|
||||
@@ -3161,7 +3166,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
storeType = type;
|
||||
}
|
||||
else {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||
invokeFunction(resolvedCall, StackValue.onStack(type));
|
||||
CallableMethod callableMethod = (CallableMethod) callable;
|
||||
|
||||
Reference in New Issue
Block a user