function inside function supported

This commit is contained in:
Pavel Talanov
2012-02-06 15:00:37 +04:00
parent d836ea04cb
commit e991565311
5 changed files with 40 additions and 2 deletions
+1 -1
View File
@@ -4,7 +4,6 @@ import js.annotations.native
native
val Math = object {
native
fun random() : Double = 0.0;
fun abs(value : Double) = 0.0
fun acos(value : Double) = 0.0
@@ -18,6 +17,7 @@ val Math = object {
fun min(vararg values : Double) = 0.0
fun sqrt(value : Double) = 0.0
fun tan(value : Double) = 0.0
fun log(value : Double) = 0.0
fun pow(base : Double, exp : Double) = 0.0
fun round(value : Double) = 0.0
@@ -395,4 +395,11 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
JsExpression value = ClassTranslator.generateClassCreationExpression(expression, context);
return AstUtil.newVar(propertyName, value);
}
@Override
@NotNull
public JsNode visitNamedFunction(@NotNull JetNamedFunction function,
@NotNull TranslationContext context) {
return FunctionTranslator.newInstance(function, context).translateAsLocalFunction();
}
}
@@ -56,9 +56,17 @@ public final class FunctionTranslator extends AbstractTranslator {
this.functionBodyContext = functionBodyContext().innerBlock(functionBody);
}
@NotNull
public JsFunction translateAsLocalFunction() {
JsName functionName = context().getNameForElement(functionDeclaration);
JsFunction function = generateFunctionObject();
function.setName(functionName);
return function;
}
@NotNull
public JsPropertyInitializer translateAsMethod() {
assert functionDeclaration instanceof JetElement;
JsName functionName = context().getNameForElement(functionDeclaration);
JsFunction function = generateFunctionObject();
return new JsPropertyInitializer(functionName.makeRef(), function);
@@ -86,4 +86,8 @@ public class FunctionTest extends AbstractExpressionTest {
System.out.println(e);
}
}
public void testFunctionInsideFunction() throws Exception {
testFooBoxIsTrue("functionInsideFunction.kt");
}
}
@@ -0,0 +1,19 @@
package foo
fun box() : Boolean{
fun f() = 3
return (((f() + f()) == 6) && (b() == 24))
}
fun b() : Int {
fun a() : Int {
fun c() = 4
return c() * 3
}
val a = 2
return a() * a
}