mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-06 18:45:09 +00:00
Fixed Avoid Error Implicit coercion of a value of type XXX to an unrelated type YYY
This commit is contained in:
@@ -128,7 +128,7 @@ public class FullMultinameAVM2Item extends AVM2Item {
|
||||
if (name instanceof IntegerValueAVM2Item) {
|
||||
name.toString(writer, localData);
|
||||
} else {
|
||||
name.toStringString(writer, localData);
|
||||
name.toString(writer, localData);
|
||||
}
|
||||
writer.append("]");
|
||||
} else {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class NameValuePair extends AVM2Item {
|
||||
if ((name instanceof ConvertAVM2Item) && ((ConvertAVM2Item)name).type.equals(TypeItem.STRING)) {
|
||||
name = name.value;
|
||||
}
|
||||
name.toStringString(writer, localData);
|
||||
name.toString(writer, localData);
|
||||
if (needsParents) {
|
||||
writer.append(")");
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.jpexs.decompiler.graph.model.TrueItem;
|
||||
import com.jpexs.helpers.Reference;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -332,13 +333,26 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
|
||||
|
||||
public GraphTextWriter appendTry(GraphTextWriter writer, LocalData localData, String implicitCoerce) throws InterruptedException {
|
||||
GraphTargetItem t = this;
|
||||
/*if (!implicitCoerce.isEmpty()) { //if implicit coerce equals explicit
|
||||
if (t instanceof ConvertAVM2Item) {
|
||||
if (!implicitCoerce.isEmpty()) { //if implicit oerce equals explicit
|
||||
/*if (t instanceof ConvertAVM2Item) {
|
||||
if (implicitCoerce.equals((((ConvertAVM2Item) t).type.toString()))) {
|
||||
t = t.value;
|
||||
}
|
||||
}*/
|
||||
if (localData.abc != null) { //its AS3
|
||||
List<String> numberTypes = Arrays.asList("int", "uint", "Number");
|
||||
String returnTypeStr = t.returnType().toString();
|
||||
|
||||
//To avoid Error: Implicit coercion of a value of type XXX to an unrelated type YYY
|
||||
if (!t.returnType().equals(TypeItem.UNBOUNDED) &&
|
||||
!implicitCoerce.equals(returnTypeStr) &&
|
||||
!(numberTypes.contains(implicitCoerce) && numberTypes.contains(returnTypeStr)) &&
|
||||
!(implicitCoerce.equals("Boolean"))
|
||||
) {
|
||||
t = new ConvertAVM2Item(null, null, t, new TypeItem(implicitCoerce));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if (!implicitCoerce.isEmpty() && Configuration.simplifyExpressions.get()) {
|
||||
t = t.simplify(implicitCoerce);
|
||||
}
|
||||
|
||||
@@ -1031,6 +1031,23 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitCoerce() {
|
||||
decompileMethod("classic_air", "testImplicitCoerce", "var j:int = 2;\r\n"
|
||||
+ "var i:int = 5;\r\n"
|
||||
+ "var r:* = Math.random();\r\n"
|
||||
+ "if(j & Number(r == 1) && 5)\r\n"
|
||||
+ "{\r\n"
|
||||
+ "trace(\"OK\");\r\n"
|
||||
+ "}\r\n"
|
||||
+ "var s:String = \"hello: \" + r;\r\n"
|
||||
+ "if(s)\r\n"
|
||||
+ "{\r\n"
|
||||
+ "trace(\"F\");\r\n"
|
||||
+ "}\r\n",
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportedVar() {
|
||||
decompileMethod("classic_air", "testImportedVar", "trace(myvar);\r\n"
|
||||
|
||||
@@ -1026,6 +1026,23 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitCoerce() {
|
||||
decompileMethod("classic", "testImplicitCoerce", "var j:int = 2;\r\n"
|
||||
+ "var i:int = 5;\r\n"
|
||||
+ "var r:* = Math.random();\r\n"
|
||||
+ "if(Boolean(j & Number(r == 1)) && Boolean(5))\r\n"
|
||||
+ "{\r\n"
|
||||
+ "trace(\"OK\");\r\n"
|
||||
+ "}\r\n"
|
||||
+ "var s:String = \"hello: \" + r;\r\n"
|
||||
+ "if(Boolean(s))\r\n"
|
||||
+ "{\r\n"
|
||||
+ "trace(\"F\");\r\n"
|
||||
+ "}\r\n",
|
||||
false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportedVar() {
|
||||
decompileMethod("classic", "testImportedVar", "trace(myvar);\r\n"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -66,6 +66,7 @@ package
|
||||
TestIfInIf;
|
||||
TestIfTry;
|
||||
TestIgnoreAndOr;
|
||||
TestImplicitCoerce;
|
||||
TestImportedVar;
|
||||
TestInc2;
|
||||
TestIncDec;
|
||||
|
||||
22
libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImplicitCoerce.as
vendored
Normal file
22
libsrc/ffdec_lib/testdata/as3_new/src/tests/TestImplicitCoerce.as
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package tests
|
||||
{
|
||||
|
||||
public class TestImplicitCoerce
|
||||
{
|
||||
public function run():void
|
||||
{
|
||||
var j:int = 2;
|
||||
var i:int = 5;
|
||||
var r:* = Math.random();
|
||||
|
||||
if (j & Number(r == 1) && 5) {
|
||||
trace("OK");
|
||||
}
|
||||
var s:String = "hello: " + r;
|
||||
|
||||
if (s){
|
||||
trace("F");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user