ExtensionFunctionCalledFromFor
This commit is contained in:
@@ -66,4 +66,8 @@ public final class ExtensionFunctionTest extends SingleFileTranslationTest {
|
|||||||
public void testExtensionFunctionCalledFromExtensionFunction() throws Exception {
|
public void testExtensionFunctionCalledFromExtensionFunction() throws Exception {
|
||||||
fooBoxTest();
|
fooBoxTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExtensionFunctionCalledFromFor() throws Exception {
|
||||||
|
fooBoxTest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -31,9 +31,7 @@ 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.reference.CallBuilder;
|
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getHasNextCallable;
|
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getIteratorFunction;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getNextFunction;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToBlock;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.convertToBlock;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newVar;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newVar;
|
||||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getLoopBody;
|
import static org.jetbrains.k2js.translate.utils.PsiUtils.getLoopBody;
|
||||||
@@ -104,7 +102,7 @@ public final class IteratorForTranslator extends ForTranslator {
|
|||||||
|
|
||||||
// kotlin iterator define hasNext as property, but java util as function, our js side expects as property
|
// kotlin iterator define hasNext as property, but java util as function, our js side expects as property
|
||||||
private static boolean isJavaUtilIterator(CallableDescriptor descriptor) {
|
private static boolean isJavaUtilIterator(CallableDescriptor descriptor) {
|
||||||
final DeclarationDescriptor declaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor declaration = descriptor.getContainingDeclaration();
|
||||||
return declaration != null && declaration.getName().getName().equals("Iterator");
|
return declaration != null && declaration.getName().getName().equals("Iterator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,8 +107,10 @@ public final class CallBuilder {
|
|||||||
private CallTranslator finish() {
|
private CallTranslator finish() {
|
||||||
if (resolvedCall == null) {
|
if (resolvedCall == null) {
|
||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
resolvedCall = ResolvedCallImpl.create(ResolutionCandidate.create(descriptor, false),
|
resolvedCall = ResolvedCallImpl.create(ResolutionCandidate.create(descriptor, descriptor.getExpectedThisObject(),
|
||||||
TemporaryBindingTrace.create(new BindingTraceContext())); //todo
|
descriptor.getReceiverParameter(),
|
||||||
|
ExplicitReceiverKind.THIS_OBJECT, false),
|
||||||
|
TemporaryBindingTrace.create(new BindingTraceContext()));
|
||||||
}
|
}
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
descriptor = resolvedCall.getCandidateDescriptor().getOriginal();
|
descriptor = resolvedCall.getCandidateDescriptor().getOriginal();
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
class SimpleEnumerator {
|
||||||
|
private var counter = 0
|
||||||
|
|
||||||
|
fun getNext(): String {
|
||||||
|
counter++;
|
||||||
|
return counter.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasMoreElements(): Boolean = counter < 1
|
||||||
|
}
|
||||||
|
|
||||||
|
class SimpleEnumeratorWrapper(private val enumerator: SimpleEnumerator) {
|
||||||
|
val hasNext: Boolean
|
||||||
|
get() = enumerator.hasMoreElements()
|
||||||
|
|
||||||
|
fun next() = enumerator.getNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun SimpleEnumerator.iterator(): SimpleEnumeratorWrapper {
|
||||||
|
return SimpleEnumeratorWrapper(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): Boolean {
|
||||||
|
var o = ""
|
||||||
|
val enumerator = SimpleEnumerator()
|
||||||
|
for (s in enumerator) {
|
||||||
|
o += s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return o == "1"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user