Int#upto
This commit is contained in:
@@ -25,10 +25,6 @@ public final class ForeachTest extends AbstractExpressionTest {
|
||||
super("for/");
|
||||
}
|
||||
|
||||
public void TODO_testForUpTo() throws Exception {
|
||||
fooBoxIsValue(10);
|
||||
}
|
||||
|
||||
public void testForIteratesOverArray() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
@@ -44,4 +44,8 @@ public final class RangeTest extends SingleFileTranslationTest {
|
||||
public void testIteratingOverRanges() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testIntUpTo() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -50,6 +50,7 @@ public final class FunctionIntrinsics {
|
||||
register(ArrayFIF.INSTANCE);
|
||||
register(TopLevelFIF.INSTANCE);
|
||||
register(NumberConversionFIF.INSTANCE);
|
||||
register(RangesFIF.INSTANCE);
|
||||
}
|
||||
|
||||
private boolean register(@NotNull FunctionIntrinsicFactory instance) {
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.k2js.translate.intrinsic.functions.factories;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic;
|
||||
|
||||
import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RangesFIF extends CompositeFIF {
|
||||
|
||||
@NotNull
|
||||
public static final FunctionIntrinsicFactory INSTANCE = new RangesFIF();
|
||||
|
||||
private RangesFIF() {
|
||||
add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() : Int {
|
||||
var sum = 0
|
||||
for (i in 0.upto(5)) {
|
||||
sum += i
|
||||
}
|
||||
return sum
|
||||
}
|
||||
@@ -42,8 +42,8 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
return answer;
|
||||
};
|
||||
|
||||
Kotlin.upto = function (from, limit, reversed) {
|
||||
return Kotlin.$new(Kotlin.NumberRange)(from, limit - from, reversed).iterator();
|
||||
Kotlin.intUpto = function (from, limit) {
|
||||
return Kotlin.$new(Kotlin.NumberRange)(from, limit - from + 1);
|
||||
};
|
||||
|
||||
Kotlin.modules = {};
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun box() : Boolean {
|
||||
var elems = ArrayList<Int>()
|
||||
for (i in 0 upto 5) {
|
||||
elems.add(i)
|
||||
}
|
||||
return elems[0] == 0 && elems[1] == 1 && elems[2] == 2 && elems[3] == 3 && elems[4] == 4 && elems[5] == 5
|
||||
}
|
||||
Reference in New Issue
Block a user