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) {
|
public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) {
|
||||||
this.receiverFunction = receiverClass;
|
this.receiverFunction = receiverClass.getOriginal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetType getThisType() {
|
public JetType getThisType() {
|
||||||
|
|||||||
@@ -964,13 +964,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
|
VariableAsFunctionResolvedCall call = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||||
|
resolvedCall = call.getVariableCall();
|
||||||
|
}
|
||||||
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
||||||
descriptor = resolvedCall.getResultingDescriptor();
|
descriptor = resolvedCall.getResultingDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
//if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||||
descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
// descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||||
}
|
//}
|
||||||
|
|
||||||
final IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(descriptor);
|
final IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(descriptor);
|
||||||
if (intrinsic != null) {
|
if (intrinsic != null) {
|
||||||
@@ -1255,14 +1259,24 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
else if (funDescriptor instanceof FunctionDescriptor) {
|
else if (funDescriptor instanceof FunctionDescriptor) {
|
||||||
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
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 {
|
else {
|
||||||
throw new UnsupportedOperationException("unknown type of callee descriptor: " + funDescriptor);
|
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;
|
boolean superCall = false;
|
||||||
if (expression.getParent() instanceof JetQualifiedExpression) {
|
if (expression.getParent() instanceof JetQualifiedExpression) {
|
||||||
final JetExpression receiverExpression = ((JetQualifiedExpression) expression.getParent()).getReceiverExpression();
|
final JetExpression receiverExpression = ((JetQualifiedExpression) expression.getParent()).getReceiverExpression();
|
||||||
@@ -1295,8 +1309,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType);
|
return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
|
||||||
assert resolvedCall != null;
|
|
||||||
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
receiver = StackValue.receiver(resolvedCall, receiver, this, null, state);
|
||||||
|
|
||||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
||||||
@@ -1324,11 +1336,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CallableMethod callableMethod;
|
CallableMethod callableMethod;
|
||||||
if (fd instanceof VariableAsFunctionDescriptor) {
|
//if (fd instanceof VariableAsFunctionDescriptor) {
|
||||||
assert !superCall;
|
// assert !superCall;
|
||||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
// callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||||
}
|
//}
|
||||||
else if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) {
|
if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) {
|
||||||
SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
|
SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
|
||||||
callableMethod = ClosureCodegen.asCallableMethod(invoke);
|
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());
|
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||||
assert resolvedCall != null;
|
assert resolvedCall != null;
|
||||||
|
|
||||||
|
if(resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
|
resolvedCall = ((VariableAsFunctionResolvedCall)resolvedCall).getFunctionCall();
|
||||||
|
}
|
||||||
|
|
||||||
if(!(resolvedCall.getResultingDescriptor() instanceof ConstructorDescriptor)) { // otherwise already
|
if(!(resolvedCall.getResultingDescriptor() instanceof ConstructorDescriptor)) { // otherwise already
|
||||||
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod, state);
|
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod, state);
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
@@ -1397,7 +1413,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
else if(descriptor instanceof ExpressionReceiver) {
|
else if(descriptor instanceof ExpressionReceiver) {
|
||||||
ExpressionReceiver expressionReceiver = (ExpressionReceiver) descriptor;
|
ExpressionReceiver expressionReceiver = (ExpressionReceiver) descriptor;
|
||||||
JetExpression expr = expressionReceiver.getExpression();
|
JetExpression expr = expressionReceiver.getExpression();
|
||||||
Type exprType = expressionType(expr);
|
Type exprType = asmType(expressionReceiver.getType());
|
||||||
gen(expr, exprType);
|
gen(expr, exprType);
|
||||||
if(type != null)
|
if(type != null)
|
||||||
StackValue.onStack(exprType).put(type, v);
|
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);
|
throw new IllegalStateException("non-declaration descriptors should be filtered out earler: " + callable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
//if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
// VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||||
if (descriptor.getOriginal() != descriptor) {
|
// if (descriptor.getOriginal() != descriptor) {
|
||||||
throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
// throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return declarationDescriptor.getOriginal();
|
return declarationDescriptor.getOriginal();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -118,9 +118,6 @@ public class BindingContextUtils {
|
|||||||
if (descriptor instanceof VariableDescriptor) {
|
if (descriptor instanceof VariableDescriptor) {
|
||||||
return (VariableDescriptor) descriptor;
|
return (VariableDescriptor) descriptor;
|
||||||
}
|
}
|
||||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
|
||||||
return ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,11 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
|||||||
public final TracingStrategy tracing = new TracingStrategy() {
|
public final TracingStrategy tracing = new TracingStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall) {
|
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);
|
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-13
@@ -17,11 +17,13 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.calls;
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.TemporaryBindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -32,18 +34,11 @@ import java.util.Map;
|
|||||||
public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
|
public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
|
||||||
private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
|
private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
|
||||||
private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
|
private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
|
||||||
private final VariableAsFunctionDescriptor variableAsFunctionDescriptor;
|
|
||||||
|
|
||||||
public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
|
public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
|
||||||
@NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
|
@NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
|
||||||
this.functionCall = functionCall;
|
this.functionCall = functionCall;
|
||||||
this.variableCall = variableCall;
|
this.variableCall = variableCall;
|
||||||
if (JetStandardClasses.isFunctionType(variableCall.getResultingDescriptor().getType())) {
|
|
||||||
variableAsFunctionDescriptor = VariableAsFunctionDescriptor.create(variableCall.getResultingDescriptor());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
variableAsFunctionDescriptor = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
|
public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
|
||||||
@@ -57,20 +52,19 @@ public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<Fun
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public FunctionDescriptor getCandidateDescriptor() {
|
public FunctionDescriptor getCandidateDescriptor() {
|
||||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
return functionCall.getResultingDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public FunctionDescriptor getResultingDescriptor() {
|
public FunctionDescriptor getResultingDescriptor() {
|
||||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
return functionCall.getResultingDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ReceiverDescriptor getReceiverArgument() {
|
public ReceiverDescriptor getReceiverArgument() {
|
||||||
ReceiverDescriptor receiverArgument = variableCall.getReceiverArgument();
|
return variableCall.getReceiverArgument();
|
||||||
return receiverArgument.exists() ? receiverArgument : functionCall.getReceiverArgument();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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();
|
createEnvironmentWithFullJdk();
|
||||||
blackBoxFile("regressions/kt865.jet");
|
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 gnu.trove.THashSet;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestResult;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||||
@@ -126,6 +127,19 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
suite.addTestSuite(aClass);
|
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) {
|
catch (NoSuchMethodException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +155,6 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|||||||
@@ -279,10 +279,6 @@ public abstract class ExpectedResolveData {
|
|||||||
|
|
||||||
|
|
||||||
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
|
DeclarationDescriptor actualDescriptor = bindingContext.get(REFERENCE_TARGET, reference);
|
||||||
if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
|
|
||||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
|
|
||||||
actualDescriptor = descriptor.getVariableDescriptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
|
"Reference `" + name + "`" + renderReferenceInContext(reference) + " is resolved into " + actualName + ".",
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
|||||||
if (calleeDescriptor instanceof ConstructorDescriptor) {
|
if (calleeDescriptor instanceof ConstructorDescriptor) {
|
||||||
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
|
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
|
||||||
}
|
}
|
||||||
else if (calleeDescriptor instanceof FunctionDescriptor && !(calleeDescriptor instanceof VariableAsFunctionDescriptor)) {
|
else if (calleeDescriptor instanceof FunctionDescriptor) {
|
||||||
FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor;
|
FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor;
|
||||||
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
|
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
|
||||||
if (fun.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
if (fun.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||||
if (target instanceof VariableAsFunctionDescriptor) {
|
|
||||||
target = ((VariableAsFunctionDescriptor)target).getVariableDescriptor();
|
|
||||||
}
|
|
||||||
if (!(target instanceof PropertyDescriptor)) {
|
if (!(target instanceof PropertyDescriptor)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,6 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) {
|
private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) {
|
||||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
|
||||||
descriptor = ((VariableAsFunctionDescriptor)descriptor).getVariableDescriptor();
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (descriptor == null) return;
|
|
||||||
}
|
|
||||||
if (descriptor instanceof VariableDescriptor) {
|
if (descriptor instanceof VariableDescriptor) {
|
||||||
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
||||||
if (variableDescriptor.isVar()) {
|
if (variableDescriptor.isVar()) {
|
||||||
|
|||||||
+4
-4
@@ -21,12 +21,12 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableAsFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
||||||
@@ -78,9 +78,9 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
|||||||
if (candidateDescriptor instanceof ExpressionAsFunctionDescriptor) {
|
if (candidateDescriptor instanceof ExpressionAsFunctionDescriptor) {
|
||||||
return translateExpressionAsFunction();
|
return translateExpressionAsFunction();
|
||||||
}
|
}
|
||||||
if (candidateDescriptor instanceof VariableAsFunctionDescriptor) {
|
//if (candidateDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||||
return translateVariableAsFunction();
|
// return translateVariableAsFunction();
|
||||||
}
|
//}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -81,12 +81,12 @@ public final class CallParametersResolver {
|
|||||||
if (!isVariableAsFunction(descriptor)) {
|
if (!isVariableAsFunction(descriptor)) {
|
||||||
return ReferenceTranslator.translateAsLocalNameReference(descriptor, context);
|
return ReferenceTranslator.translateAsLocalNameReference(descriptor, context);
|
||||||
}
|
}
|
||||||
VariableDescriptor variableDescriptor =
|
//VariableDescriptor variableDescriptor =
|
||||||
getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)descriptor);
|
// getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)descriptor);
|
||||||
if (variableDescriptor instanceof PropertyDescriptor) {
|
//if (variableDescriptor instanceof PropertyDescriptor) {
|
||||||
return getterCall((PropertyDescriptor)variableDescriptor);
|
// return getterCall((PropertyDescriptor)variableDescriptor);
|
||||||
}
|
//}
|
||||||
return ReferenceTranslator.translateAsLocalNameReference(variableDescriptor, context);
|
return ReferenceTranslator.translateAsLocalNameReference(descriptor, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: inspect
|
//TODO: inspect
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableAsFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
@@ -95,8 +94,8 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExpressionAsFunction() {
|
private boolean isExpressionAsFunction() {
|
||||||
return descriptor instanceof ExpressionAsFunctionDescriptor ||
|
return descriptor instanceof ExpressionAsFunctionDescriptor;// ||
|
||||||
descriptor instanceof VariableAsFunctionDescriptor;
|
//descriptor instanceof VariableAsFunctionDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -142,8 +141,8 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExtensionFunctionLiteral() {
|
private boolean isExtensionFunctionLiteral() {
|
||||||
boolean isLiteral = descriptor instanceof VariableAsFunctionDescriptor
|
boolean isLiteral = //descriptor instanceof VariableAsFunctionDescriptor ||
|
||||||
|| descriptor instanceof ExpressionAsFunctionDescriptor;
|
descriptor instanceof ExpressionAsFunctionDescriptor;
|
||||||
return isExtensionFunction() && isLiteral;
|
return isExtensionFunction() && isLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,10 +194,10 @@ public final class BindingUtils {
|
|||||||
public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context,
|
public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context,
|
||||||
@NotNull JetReferenceExpression reference) {
|
@NotNull JetReferenceExpression reference) {
|
||||||
DeclarationDescriptor referencedDescriptor = context.get(BindingContext.REFERENCE_TARGET, reference);
|
DeclarationDescriptor referencedDescriptor = context.get(BindingContext.REFERENCE_TARGET, reference);
|
||||||
if (isVariableAsFunction(referencedDescriptor)) {
|
//if (isVariableAsFunction(referencedDescriptor)) {
|
||||||
assert referencedDescriptor != null;
|
// assert referencedDescriptor != null;
|
||||||
return getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)referencedDescriptor);
|
// return getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)referencedDescriptor);
|
||||||
}
|
//}
|
||||||
return referencedDescriptor;
|
return referencedDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,17 +126,17 @@ public final class JsDescriptorUtils {
|
|||||||
return (ClassDescriptor)superClassDescriptor;
|
return (ClassDescriptor)superClassDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
//@NotNull
|
||||||
public static VariableDescriptor getVariableDescriptorForVariableAsFunction
|
//public static VariableDescriptor getVariableDescriptorForVariableAsFunction
|
||||||
(@NotNull VariableAsFunctionDescriptor descriptor) {
|
// (@NotNull VariableAsFunctionDescriptor descriptor) {
|
||||||
VariableDescriptor functionVariable = descriptor.getVariableDescriptor();
|
// VariableDescriptor functionVariable = descriptor.getVariableDescriptor();
|
||||||
assert functionVariable != null;
|
// assert functionVariable != null;
|
||||||
return functionVariable;
|
// return functionVariable;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isVariableAsFunction(@Nullable DeclarationDescriptor referencedDescriptor) {
|
public static boolean isVariableAsFunction(@Nullable DeclarationDescriptor referencedDescriptor) {
|
||||||
return referencedDescriptor instanceof VariableAsFunctionDescriptor;
|
return false;//referencedDescriptor instanceof VariableAsFunctionDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user