Fix for a bug that caused invalid code generated for calling extension from another extension.
This commit is contained in:
@@ -78,4 +78,16 @@ public final class ExtensionFunctionTest extends SingleFileTranslationTest {
|
||||
public void testExtensionFunctionCalledFromFor() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testImplicitReceiverInExtension() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testExtensionForSuperclass() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testSuperClassMemberInExtension() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -28,7 +28,7 @@ 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.getExpectedReceiverDescriptor;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getDeclarationDescriptorForExtensionCallReceiver;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -106,8 +106,7 @@ public final class CallParametersResolver {
|
||||
if (qualifier != null) {
|
||||
return qualifier;
|
||||
}
|
||||
DeclarationDescriptor expectedReceiverDescriptor = getExpectedReceiverDescriptor(resolvedCall.getResultingDescriptor());
|
||||
assert expectedReceiverDescriptor != null;
|
||||
return TranslationUtils.getThisObject(context, expectedReceiverDescriptor);
|
||||
DeclarationDescriptor receiverDescriptor = getDeclarationDescriptorForExtensionCallReceiver(resolvedCall);
|
||||
return TranslationUtils.getThisObject(context, receiverDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
@@ -231,4 +234,18 @@ public final class JsDescriptorUtils {
|
||||
!isDefaultAccessor(propertyDescriptor.getGetter()) ||
|
||||
!isDefaultAccessor(propertyDescriptor.getSetter());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DeclarationDescriptor getDeclarationDescriptorForExtensionCallReceiver(
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall
|
||||
) {
|
||||
ReceiverDescriptor receiverArgument = resolvedCall.getReceiverArgument();
|
||||
if (receiverArgument instanceof ExtensionReceiver) {
|
||||
return ((ExtensionReceiver) receiverArgument).getDeclarationDescriptor();
|
||||
}
|
||||
if (receiverArgument instanceof ClassReceiver) {
|
||||
return ((ClassReceiver)receiverArgument).getDeclarationDescriptor();
|
||||
}
|
||||
throw new IllegalStateException("Unexpected receiver of type " + receiverArgument.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
open fun c() = 2
|
||||
}
|
||||
|
||||
class B(): A() {
|
||||
override fun c() = 3
|
||||
}
|
||||
|
||||
fun B.t() = d() + 1
|
||||
|
||||
fun A.d() = c() + 3
|
||||
|
||||
fun box() : Boolean {
|
||||
return A().d() == 5 && B().d() == 6 && B().t() == 7
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package foo
|
||||
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + toString() + suffix
|
||||
|
||||
fun box() : Boolean {
|
||||
return ("mama".toPrefixedString(suffix="321", prefix="papa") == "papamama321")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
open fun c() = 2
|
||||
}
|
||||
|
||||
class B(): A() {
|
||||
}
|
||||
|
||||
fun B.d() = c() + 3
|
||||
|
||||
fun box() : Boolean {
|
||||
return B().d() == 5
|
||||
}
|
||||
Reference in New Issue
Block a user