Fixed: #2391 Double not operator in ternar operator expression

This commit is contained in:
Jindra Petřík
2025-03-22 21:35:12 +01:00
parent a685050dff
commit a992adb5c0
9 changed files with 38 additions and 3 deletions

View File

@@ -77,7 +77,7 @@ public class TernarOpItem extends GraphTargetItem {
if (expression.getPrecedence() >= precedence) {
writer.append("(");
}
expression.toString(writer, localData);
expression.toStringBoolean(writer, localData);
if (expression.getPrecedence() >= precedence) {
writer.append(")");
}

View File

@@ -1997,6 +1997,15 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testTernarOperator2() {
decompileMethod("classic_air", "testTernarOperator2", "var b:Boolean = true;\r\n"
+ "var i:int = 1;\r\n"
+ "var j:int = int(b ? i : i + 1);\r\n"
+ "var k:int = int(i ? j : j + 1);\r\n",
false);
}
@Test
public void testTry() {
decompileMethod("classic_air", "testTry", "var i:int = 0;\r\n"

View File

@@ -1983,6 +1983,15 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testTernarOperator2() {
decompileMethod("classic", "testTernarOperator2", "var b:Boolean = true;\r\n"
+ "var i:int = 1;\r\n"
+ "var j:int = b ? i : i + 1;\r\n"
+ "var k:int = Boolean(i) ? j : j + 1;\r\n",
false);
}
@Test
public void testTry() {
decompileMethod("classic", "testTry", "var i:int = 0;\r\n"

View File

@@ -122,6 +122,7 @@ package
TestSwitchDefault;
TestSwitchIf;
TestTernarOperator;
TestTernarOperator2;
TestTry;
TestTryIf;
TestTryReturn;

View File

@@ -24,7 +24,7 @@ package tests
this.ti = ti && (ti = new TestClass());
var a = ti && (ti = new TestClass());
var a:* = ti && (ti = new TestClass());
var b:int = 1 + (i || j); //no coercion
@@ -33,7 +33,7 @@ package tests
return ti && (ti = new TestClass());
}
public function test(p:TestInterface)
public function test(p:TestInterface): void
{
}

View File

@@ -0,0 +1,14 @@
package tests
{
public class TestTernarOperator2
{
public function run():*
{
var b:Boolean = true;
var i:int = 1;
var j:int = b ? i : i + 1;
var k:int = i ? j : j + 1;
}
}
}