This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit fd7b81f4448db0f5eb70f22208c9144549cc4806 Author: Josh Tynjala <[email protected]> AuthorDate: Wed Feb 6 08:36:10 2019 -0800 ParametersEmitter: fixed automatic type coercion and added some tests (closes #74) --- .../js/jx/FunctionCallArgumentsEmitter.java | 10 +++++-- .../codegen/js/royale/TestRoyaleExpressions.java | 34 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java index 40b6302..c92f189 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java @@ -61,17 +61,21 @@ public class FunctionCallArgumentsEmitter extends JSSubEmitter implements for (int i = 0; i < len; i++) { IExpressionNode argumentNode = (IExpressionNode) node.getChild(i); - IParameterDefinition paramDef = null; + IDefinition paramTypeDef = null; if (paramDefs != null && paramDefs.length > i) { - paramDef = paramDefs[i]; + IParameterDefinition paramDef = paramDefs[i]; if (paramDef.isRest()) { paramDef = null; } + if (paramDef != null) + { + paramTypeDef = paramDef.resolveType(getProject()); + } } - getEmitter().emitAssignmentCoercion(argumentNode, paramDef); + getEmitter().emitAssignmentCoercion(argumentNode, paramTypeDef); if (i < len - 1) { diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java index 93db140..56b6363 100644 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java +++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java @@ -1523,7 +1523,7 @@ public class TestRoyaleExpressions extends TestGoogExpressions @Test public void testVisitCallFunctionReturnedFromFunction() { - IFunctionCallNode node = (IFunctionCallNode) getNode("function foo(a:String, b:String):Function { return null }; return foo(3, 4)(1, 2);", + IFunctionCallNode node = (IFunctionCallNode) getNode("function foo(a:int, b:int):Function { return null }; return foo(3, 4)(1, 2);", IFunctionCallNode.class); asBlockWalker.visitFunctionCall(node); assertOut("foo(3, 4)(1, 2)"); @@ -1571,6 +1571,38 @@ public class TestRoyaleExpressions extends TestGoogExpressions assertOut("return 4294967173"); } + @Test + public void testVisitFunctionCallWithIntParameterNegative() + { + IFunctionCallNode node = (IFunctionCallNode) getNode("function a(foo:int):void {}; a(-123)", IFunctionCallNode.class); + asBlockWalker.visitFunctionCall(node); + assertOut("a(-123)"); + } + + @Test + public void testVisitFunctionCallWithIntParameterDecimal() + { + IFunctionCallNode node = (IFunctionCallNode) getNode("function a(foo:int):void {}; a(123.4)", IFunctionCallNode.class); + asBlockWalker.visitFunctionCall(node); + assertOut("a(123)"); + } + + @Test + public void testVisitFunctionCallWithUintParameterNegative() + { + IFunctionCallNode node = (IFunctionCallNode) getNode("function a(foo:uint):void {}; a(-123)", IFunctionCallNode.class); + asBlockWalker.visitFunctionCall(node); + assertOut("a(4294967173)"); + } + + @Test + public void testVisitFunctionCallWithUintParameterDecimal() + { + IFunctionCallNode node = (IFunctionCallNode) getNode("function a(foo:uint):void {}; a(123.4)", IFunctionCallNode.class); + asBlockWalker.visitFunctionCall(node); + assertOut("a(123)"); + } + protected IBackend createBackend() { return new RoyaleBackend();
