incorporating Sveta's patch on VariableAsFunctionResolvedCall
This commit is contained in:
@@ -79,7 +79,7 @@ public class CallableMethod implements Callable {
|
||||
}
|
||||
|
||||
public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) {
|
||||
this.receiverFunction = receiverClass;
|
||||
this.receiverFunction = receiverClass.getOriginal();
|
||||
}
|
||||
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -964,13 +964,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
}
|
||||
else {
|
||||
if(resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
VariableAsFunctionResolvedCall call = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||
resolvedCall = call.getVariableCall();
|
||||
}
|
||||
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
||||
descriptor = resolvedCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||
descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||
}
|
||||
//if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||
// descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||
//}
|
||||
|
||||
final IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(descriptor);
|
||||
if (intrinsic != null) {
|
||||
@@ -1255,14 +1259,24 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
else if (funDescriptor instanceof FunctionDescriptor) {
|
||||
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
||||
return invokeFunction(expression, fd, receiver);
|
||||
if(resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
VariableAsFunctionResolvedCall call = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||
ResolvedCallWithTrace<FunctionDescriptor> functionCall = call.getFunctionCall();
|
||||
return invokeFunction(expression, functionCall.getResultingDescriptor(), receiver, functionCall);
|
||||
}
|
||||
else {
|
||||
return invokeFunction(expression, fd, receiver, resolvedCall);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("unknown type of callee descriptor: " + funDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private StackValue invokeFunction(JetCallExpression expression, DeclarationDescriptor fd, StackValue receiver) {
|
||||
private StackValue invokeFunction(JetCallExpression expression,
|
||||
DeclarationDescriptor fd,
|
||||
StackValue receiver,
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall) {
|
||||
boolean superCall = false;
|
||||
if (expression.getParent() instanceof JetQualifiedExpression) {
|
||||
final JetExpression receiverExpression = ((JetQualifiedExpression) expression.getParent()).getReceiverExpression();
|
||||
@@ -1295,8 +1309,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType);
|
||||
}
|
||||
else {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||
assert resolvedCall != null;
|
||||
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
||||
|
||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
||||
@@ -1324,11 +1336,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
CallableMethod callableMethod;
|
||||
if (fd instanceof VariableAsFunctionDescriptor) {
|
||||
assert !superCall;
|
||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||
}
|
||||
else if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) {
|
||||
//if (fd instanceof VariableAsFunctionDescriptor) {
|
||||
// assert !superCall;
|
||||
// callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||
//}
|
||||
if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) {
|
||||
SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
|
||||
callableMethod = ClosureCodegen.asCallableMethod(invoke);
|
||||
}
|
||||
@@ -1351,6 +1363,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||
assert resolvedCall != null;
|
||||
|
||||
if(resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
resolvedCall = ((VariableAsFunctionResolvedCall)resolvedCall).getFunctionCall();
|
||||
}
|
||||
|
||||
if(!(resolvedCall.getResultingDescriptor() instanceof ConstructorDescriptor)) { // otherwise already
|
||||
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod, state);
|
||||
receiver.put(receiver.type, v);
|
||||
@@ -1397,7 +1413,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
else if(descriptor instanceof ExpressionReceiver) {
|
||||
ExpressionReceiver expressionReceiver = (ExpressionReceiver) descriptor;
|
||||
JetExpression expr = expressionReceiver.getExpression();
|
||||
Type exprType = expressionType(expr);
|
||||
Type exprType = asmType(expressionReceiver.getType());
|
||||
gen(expr, exprType);
|
||||
if(type != null)
|
||||
StackValue.onStack(exprType).put(type, v);
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public static VariableAsFunctionDescriptor create(@NotNull VariableDescriptor variableDescriptor) {
|
||||
JetType outType = variableDescriptor.getType();
|
||||
assert outType != null;
|
||||
VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor);
|
||||
FunctionDescriptorUtil.initializeFromFunctionType(result, outType, variableDescriptor.getExpectedThisObject());
|
||||
return result;
|
||||
}
|
||||
|
||||
private final VariableDescriptor variableDescriptor;
|
||||
|
||||
private VariableAsFunctionDescriptor(VariableDescriptor variableDescriptor) {
|
||||
super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName(), Kind.DECLARATION);
|
||||
this.variableDescriptor = variableDescriptor;
|
||||
}
|
||||
|
||||
public VariableDescriptor getVariableDescriptor() {
|
||||
return variableDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
throw new UnsupportedOperationException("Should not be copied for overriding");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
@@ -49,12 +49,12 @@ public class BindingContextUtils {
|
||||
throw new IllegalStateException("non-declaration descriptors should be filtered out earler: " + callable);
|
||||
}
|
||||
}
|
||||
if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||
if (descriptor.getOriginal() != descriptor) {
|
||||
throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
||||
}
|
||||
}
|
||||
//if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
// VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||
// if (descriptor.getOriginal() != descriptor) {
|
||||
// throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
||||
// }
|
||||
//}
|
||||
return declarationDescriptor.getOriginal();
|
||||
}
|
||||
};
|
||||
@@ -118,9 +118,6 @@ public class BindingContextUtils {
|
||||
if (descriptor instanceof VariableDescriptor) {
|
||||
return (VariableDescriptor) descriptor;
|
||||
}
|
||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||
return ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,11 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
public final TracingStrategy tracing = new TracingStrategy() {
|
||||
@Override
|
||||
public <D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall) {
|
||||
trace.record(REFERENCE_TARGET, reference, resolvedCall.getResultingDescriptor());
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
descriptor = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall().getResultingDescriptor();
|
||||
}
|
||||
trace.record(REFERENCE_TARGET, reference, descriptor);
|
||||
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
||||
}
|
||||
|
||||
|
||||
+7
-13
@@ -17,11 +17,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.calls;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,18 +34,11 @@ import java.util.Map;
|
||||
public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
|
||||
private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
|
||||
private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
|
||||
private final VariableAsFunctionDescriptor variableAsFunctionDescriptor;
|
||||
|
||||
public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
|
||||
@NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
|
||||
this.functionCall = functionCall;
|
||||
this.variableCall = variableCall;
|
||||
if (JetStandardClasses.isFunctionType(variableCall.getResultingDescriptor().getType())) {
|
||||
variableAsFunctionDescriptor = VariableAsFunctionDescriptor.create(variableCall.getResultingDescriptor());
|
||||
}
|
||||
else {
|
||||
variableAsFunctionDescriptor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
|
||||
@@ -57,20 +52,19 @@ public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<Fun
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getCandidateDescriptor() {
|
||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||
return functionCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getResultingDescriptor() {
|
||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||
return functionCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverDescriptor getReceiverArgument() {
|
||||
ReceiverDescriptor receiverArgument = variableCall.getReceiverArgument();
|
||||
return receiverArgument.exists() ? receiverArgument : functionCall.getReceiverArgument();
|
||||
return variableCall.getReceiverArgument();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box() : String {
|
||||
val y = 12
|
||||
val op = { (x:Int) -> (x + y).toString() }
|
||||
|
||||
val op2 : Int.(Int) -> String = { op(this + it) }
|
||||
|
||||
return if("27" == 5.op2(10)) "OK" else "fail"
|
||||
}
|
||||
@@ -71,4 +71,9 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
||||
createEnvironmentWithFullJdk();
|
||||
blackBoxFile("regressions/kt865.jet");
|
||||
}
|
||||
|
||||
public void testKtNested2() throws Exception {
|
||||
createEnvironmentWithMockJdk(CompilerSpecialMode.BUILTINS);
|
||||
blackBoxFile("extensionFunctions/nested2.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.local.CoreLocalFileSystem;
|
||||
import gnu.trove.THashSet;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||
@@ -126,6 +127,19 @@ public class TestlibTest extends CodegenTestCase {
|
||||
suite.addTestSuite(aClass);
|
||||
}
|
||||
}
|
||||
catch (final VerifyError e) {
|
||||
suite.addTest(new TestCase(aClass.getName()) {
|
||||
@Override
|
||||
public int countTestCases() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(TestResult result) {
|
||||
result.addError(this, new RuntimeException(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
}
|
||||
}
|
||||
@@ -141,7 +155,6 @@ public class TestlibTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
return suite;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -279,10 +279,6 @@ public abstract class ExpectedResolveData {
|
||||
|
||||
|
||||
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
|
||||
if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
|
||||
actualDescriptor = descriptor.getVariableDescriptor();
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
|
||||
|
||||
Reference in New Issue
Block a user