Fix a bug which caused incorrectly generated js when you call extension literal from extension function.
This commit is contained in:
@@ -27,7 +27,6 @@ import org.mozilla.javascript.JavaScriptException;
|
||||
*/
|
||||
public final class MiscTest extends AbstractExpressionTest {
|
||||
|
||||
|
||||
public MiscTest() {
|
||||
super("misc/");
|
||||
}
|
||||
@@ -122,4 +121,8 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
public void testElvis() throws Exception {
|
||||
checkFooBoxIsTrue("elvis.kt");
|
||||
}
|
||||
|
||||
public void testExtensionLiteralCalledInsideExtensionFunction() throws Exception {
|
||||
checkFooBoxIsTrue("extensionLiteralCalledInsideExtensionFunction.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -19,14 +19,16 @@ package org.jetbrains.k2js.translate.reference;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCallWithTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getExpectedReceiverDescriptor;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -34,10 +36,10 @@ import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
|
||||
public final class CallParametersResolver {
|
||||
|
||||
public static CallParameters resolveCallParameters(@Nullable JsExpression qualifier,
|
||||
@Nullable JsExpression callee,
|
||||
@NotNull CallableDescriptor descriptor,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> call,
|
||||
@NotNull TranslationContext context) {
|
||||
@Nullable JsExpression callee,
|
||||
@NotNull CallableDescriptor descriptor,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> call,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new CallParametersResolver(qualifier, callee, descriptor, call, context)).resolve();
|
||||
}
|
||||
|
||||
@@ -55,10 +57,10 @@ public final class CallParametersResolver {
|
||||
private final boolean isExtensionCall;
|
||||
|
||||
public CallParametersResolver(@Nullable JsExpression qualifier,
|
||||
@Nullable JsExpression callee,
|
||||
@NotNull CallableDescriptor descriptor,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> call,
|
||||
@NotNull TranslationContext context) {
|
||||
@Nullable JsExpression callee,
|
||||
@NotNull CallableDescriptor descriptor,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> call,
|
||||
@NotNull TranslationContext context) {
|
||||
this.qualifier = qualifier;
|
||||
this.callee = callee;
|
||||
this.descriptor = descriptor;
|
||||
@@ -104,7 +106,7 @@ public final class CallParametersResolver {
|
||||
if (qualifier != null) {
|
||||
return qualifier;
|
||||
}
|
||||
DeclarationDescriptor expectedReceiverDescriptor = getExpectedReceiverDescriptor(descriptor);
|
||||
DeclarationDescriptor expectedReceiverDescriptor = getExpectedReceiverDescriptor(resolvedCall.getResultingDescriptor());
|
||||
assert expectedReceiverDescriptor != null;
|
||||
return TranslationUtils.getThisObject(context, expectedReceiverDescriptor);
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
fun A.create(init : A.() -> Unit) : A {
|
||||
init()
|
||||
return this
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
val a = A().create {
|
||||
c = 1 + t
|
||||
}
|
||||
return a.c == 4
|
||||
}
|
||||
|
||||
class A() {
|
||||
val t = 3
|
||||
var c = 2
|
||||
}
|
||||
Reference in New Issue
Block a user