diff --git a/CHANGELOG.md b/CHANGELOG.md index e647c6c1b..0789f822e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Tag dependency checking - [#1884] Memory search - Logged exception when cannot get page range - [#1884] Memory search - Exception on sorting by pid +- [#1006] AS3 - Warning - Function value used where type Boolean was expected ### Changed - Quick search needs minimum of 3 characters @@ -2697,6 +2698,7 @@ All notable changes to this project will be documented in this file. [#1765]: https://www.free-decompiler.com/flash/issues/1765 [#1884]: https://www.free-decompiler.com/flash/issues/1884 [#1897]: https://www.free-decompiler.com/flash/issues/1897 +[#1006]: https://www.free-decompiler.com/flash/issues/1006 [#1888]: https://www.free-decompiler.com/flash/issues/1888 [#1895]: https://www.free-decompiler.com/flash/issues/1895 [#1896]: https://www.free-decompiler.com/flash/issues/1896 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 44df30e45..5c00fa58d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -347,7 +347,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { if (!t.returnType().equals(TypeItem.UNBOUNDED) && !implicitCoerce.equals(returnTypeStr) && !(numberTypes.contains(implicitCoerce) && numberTypes.contains(returnTypeStr)) && - !(implicitCoerce.equals("Boolean")) + !(implicitCoerce.equals("Boolean") && !returnTypeStr.equals("Function")) ) { t = new ConvertAVM2Item(null, null, t, new TypeItem(implicitCoerce)); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java index 1fde6259a..68c0274b8 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java @@ -222,13 +222,17 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile @Test public void testConvert() { - decompileMethod("classic_air", "testConvert", "var s:* = null;\r\n" - + "var i:int = 0;\r\n" - + "var a:* = undefined;\r\n" - + "s = \"a\";\r\n" - + "i = int(s);\r\n" - + "var j:int;\r\n" - + "s = String(j = n);\r\n" + decompileMethod("classic_air", "testConvert", "var a:*;\r\n" + + "var o:Object;\r\n" + + "var v:Vector.;\r\n" + + "var x:XML;\r\n" + + "var xlist:XMLList;\r\n" + + "var lc:LocalClass;\r\n" + + "var f:Function;\r\n" + + "var s:String = \"a\";\r\n" + + "var i:int = s;\r\n" + + "var j:int = n;\r\n" + + "s = String(j);\r\n" + "s = ns;\r\n" + "s = String(i == 4 ? \"\" : i);\r\n" + "s = i == 4 ? \"\" : String(i);\r\n" @@ -237,13 +241,13 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "i = 4 * 5;\r\n" + "i = a * 6;\r\n" + "i = a;\r\n" - + "var o:Object = {\r\n" + + "o = {\r\n" + "0:\"A\",\r\n" + "1:\"B\",\r\n" + "2:\"C\"\r\n" + "};\r\n" + "i = int(s.charAt(10));\r\n" - + "var v:Vector. = new Vector.();\r\n" + + "v = new Vector.();\r\n" + "v.push(\"A\");\r\n" + "v.push(\"B\");\r\n" + "i = int(v[0]);\r\n" @@ -253,21 +257,40 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile + "i = int(prot);\r\n" + "s = prot;\r\n" + "s = String(getTimer());\r\n" - + "var x:XML;\r\n" - + "s = x = \r\n" + + "x = \r\n" + "1\r\n" + "2\r\n" + "3\r\n" + ";\r\n" + + "s = x;\r\n" + "trace(\"a\");\r\n" - + "var xlist:XMLList = x.item;\r\n" + + "xlist = x.item;\r\n" + "trace(\"b\");\r\n" + "i = int(xlist[i].@id);\r\n" + "trace(\"c\");\r\n" + "i = int(x.item[i].@id);\r\n" - + "var lc:LocalClass;\r\n" - + "i = (lc = new LocalClass()).attr;\r\n" - + "s = String(lc.attr);\r\n", + + "lc = new LocalClass();\r\n" + + "i = lc.attr;\r\n" + + "s = String(lc.attr);\r\n" + + "f = function():void\r\n" + + "{\r\n" + + "};\r\n" + + "if(Boolean(f))\r\n" + + "{\r\n" + + "trace(\"OK\");\r\n" + + "}\r\n" + + "if(i)\r\n" + + "{\r\n" + + "trace(i);\r\n" + + "}\r\n" + + "if(s)\r\n" + + "{\r\n" + + "trace(s);\r\n" + + "}\r\n" + + "if(o)\r\n" + + "{\r\n" + + "trace(\"obj\");\r\n" + + "}\r\n", false); } @@ -613,14 +636,12 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile @Test public void testForEachReturn2() { - decompileMethod("classic_air", "testForEachReturn2", "var item:* = undefined;\r\n" - + "var obj:* = null;\r\n" + decompileMethod("classic_air", "testForEachReturn2", "var obj:* = null;\r\n" + "var x:int = 5;\r\n" + "if(x != null)\r\n" + "{\r\n" + "obj = {};\r\n" - + "item = {};\r\n" - + "for each(item in obj)\r\n" + + "for each(var item in obj)\r\n" + "{\r\n" + "switch(item[\"key\"])\r\n" + "{\r\n" @@ -1653,9 +1674,9 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testUndefined", "var i:int;\r\n" + "var j:int;\r\n" + "var c:int;\r\n" - + "var f:*;\r\n" + + "var f:Function;\r\n" + "c = 5 + i;\r\n" - + "f = function():*\r\n" + + "f = function():void\r\n" + "{\r\n" + "trace(c);\r\n" + "trace(j);\r\n" diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java index 98d1c496b..b6294dd5b 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java @@ -221,7 +221,11 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testConvert() { - decompileMethod("classic", "testConvert", "var s:String = null;\r\n" + decompileMethod("classic", "testConvert", "var x:XML;\r\n" + + "var xlist:XMLList;\r\n" + + "var lc:LocalClass;\r\n" + + "var f:Function;\r\n" + + "var s:String = null;\r\n" + "var i:int = 0;\r\n" + "var a:* = undefined;\r\n" + "s = \"a\";\r\n" @@ -252,21 +256,40 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "i = int(prot);\r\n" + "s = prot;\r\n" + "s = String(getTimer());\r\n" - + "var x:XML = \r\n" + + "x = \r\n" + "1\r\n" + "2\r\n" + "3\r\n" + ";\r\n" + "s = x;\r\n" + "trace(\"a\");\r\n" - + "var xlist:XMLList = x.item;\r\n" + + "xlist = x.item;\r\n" + "trace(\"b\");\r\n" + "i = int(xlist[i].@id);\r\n" + "trace(\"c\");\r\n" + "i = int(x.item[i].@id);\r\n" - + "var lc:LocalClass = new LocalClass();\r\n" + + "lc = new LocalClass();\r\n" + "i = lc.attr;\r\n" - + "s = String(lc.attr);\r\n", + + "s = String(lc.attr);\r\n" + + "f = function():void\r\n" + + "{\r\n" + + "};\r\n" + + "if(Boolean(f))\r\n" + + "{\r\n" + + "trace(\"OK\");\r\n" + + "}\r\n" + + "if(Boolean(i))\r\n" + + "{\r\n" + + "trace(i);\r\n" + + "}\r\n" + + "if(Boolean(s))\r\n" + + "{\r\n" + + "trace(s);\r\n" + + "}\r\n" + + "if(Boolean(o))\r\n" + + "{\r\n" + + "trace(\"obj\");\r\n" + + "}\r\n", false); } @@ -609,22 +632,21 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testForEachReturn2() { - decompileMethod("classic", "testForEachReturn2", "var _loc3_:* = undefined;\r\n" - + "var _loc1_:* = null;\r\n" - + "var _loc2_:* = 5;\r\n" - + "if(_loc2_ != null)\r\n" + decompileMethod("classic", "testForEachReturn2", "var item:* = undefined;\r\n" + + "var obj:* = null;\r\n" + + "var x:* = 5;\r\n" + + "if(x != null)\r\n" + "{\r\n" - + "_loc1_ = {};\r\n" - + "_loc3_ = {};\r\n" - + "for each(_loc3_ in _loc1_)\r\n" + + "obj = {};\r\n" + + "for each(item in obj)\r\n" + "{\r\n" - + "switch(_loc3_[\"key\"])\r\n" + + "switch(item[\"key\"])\r\n" + "{\r\n" + "case 1:\r\n" + "case 2:\r\n" + "case 3:\r\n" + "case 4:\r\n" - + "return _loc3_;\r\n" + + "return item;\r\n" + "}\r\n" + "}\r\n" + "}\r\n" @@ -1653,7 +1675,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "var j:int = 0;\r\n" + "var c:int = 0;\r\n" + "c = 5 + i;\r\n" - + "var f:* = function():*\r\n" + + "var f:Function = function():void\r\n" + "{\r\n" + "trace(c);\r\n" + "trace(j);\r\n" diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf index e1f309e02..0eb6eb5e2 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf index 2037716d6..4fe4fb637 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/build_air_debug.bat b/libsrc/ffdec_lib/testdata/as3_new/build_air_debug.bat index 105b1199d..96921eac3 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/build_air_debug.bat +++ b/libsrc/ffdec_lib/testdata/as3_new/build_air_debug.bat @@ -1,4 +1,5 @@ @echo off set COMPILERKIND=air set SWFNAME=as3_new -call c:\air\bin\mxmlc.bat -warnings=false -debug=true -output bin/%SWFNAME%.%COMPILERKIND%.swf src/Main.as 1> buildlog.%COMPILERKIND%.txt 2>&1 \ No newline at end of file +call c:\air\bin\mxmlc.bat -debug=true -output bin/%SWFNAME%.%COMPILERKIND%.swf src/Main.as 1> buildlog.%COMPILERKIND%.txt 2>&1 +rem -warnings=false \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as3_new/build_flex_debug.bat b/libsrc/ffdec_lib/testdata/as3_new/build_flex_debug.bat index 0e5cd7aab..69d826549 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/build_flex_debug.bat +++ b/libsrc/ffdec_lib/testdata/as3_new/build_flex_debug.bat @@ -1,4 +1,5 @@ @echo off set COMPILERKIND=flex set SWFNAME=as3_new -c:\flex\bin\mxmlc.exe -warnings=false -debug=true -output bin/%SWFNAME%.%COMPILERKIND%.swf src/Main.as 1> buildlog.%COMPILERKIND%.txt 2>&1 \ No newline at end of file +c:\flex\bin\mxmlc.exe -debug=true -output bin/%SWFNAME%.%COMPILERKIND%.swf src/Main.as 1> buildlog.%COMPILERKIND%.txt 2>&1 +rem -warnings=false \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallCall.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallCall.as index bbc62332a..18b4eb898 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallCall.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestCallCall.as @@ -6,8 +6,8 @@ package tests { public function run() : * { - var o = new getDefinitionByName("Object")(); - var o2 = new (getDefinitionByName("Object"))(); + var o:* = new getDefinitionByName("Object")(); + var o2:* = new (getDefinitionByName("Object"))(); } } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as index b6e0dbc2a..22456eb59 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestConvert.as @@ -69,7 +69,24 @@ package tests var lc:LocalClass = new LocalClass(); i = lc.attr; - s = String(lc.attr); + s = String(lc.attr); + + + var f:Function = function():void {}; + if (Boolean(f)) { + trace("OK"); + } + + if (i) { + trace(i); + } + if (s) { + trace(s); + } + + if (o) { + trace("obj"); + } } } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestForEachReturn2.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestForEachReturn2.as index 050e6533f..6eabc59bd 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestForEachReturn2.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestForEachReturn2.as @@ -6,12 +6,11 @@ package tests public function run():* { var obj:* = null; - var x = 5; + var x:* = 5; if (x != null) { obj = {}; - var item = {}; - for each (var item in obj) + for each (var item:* in obj) { switch (item["key"]) { diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestHello.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestHello.as index 14adab912..32a289232 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestHello.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestHello.as @@ -5,7 +5,7 @@ package tests { public function run():* { - trace("hello"); + trace("hello"); } } } \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as index 28eacd50e..110f354fd 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestNames.as @@ -9,7 +9,7 @@ package tests { myInternal var neco:int; myInternal2 var neco:int; - var nic:int; + internal var nic:int; public function run():* { diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestUndefined.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestUndefined.as index 0ac78b40e..2903e0568 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestUndefined.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests/TestUndefined.as @@ -8,7 +8,7 @@ package tests var i:int; var j:int var c:int = 5 + i; - var f = function() { + var f:Function = function(): void { trace(c); trace(j); };