as3hx icon indicating copy to clipboard operation
as3hx copied to clipboard

Reflection issues

Open mastef opened this issue 8 years ago • 0 comments
trafficstars

Could be related to #35

  • Issue 1 : When param type is unknown conversion doesn't happen ( see cases with paramNoType )
  • Issue 2 : Reflect.setField conversion is wrong for multiple level objects

as3 code for example:

package {
    public class Issue {
        public function Issue() {
            var paramNoType = "hello";
            if(this[paramNoType].bool == true)
            {
                this[paramNoType].bool = false;
                this[paramNoType].prop1.prop2 = "nothing";
            }

            var paramString:String = "hello";
            if(this[paramString].bool == true)
            {
                this[paramString].bool = false;
                this[paramString].prop1.prop2 = "nothing";
            }

            var paramDynamic:* = "hello";
            if(this[paramDynamic].bool == true)
            {
                this[paramDynamic].bool = false;
                this[paramDynamic].prop1.prop2 = "nothing";
            }
        }

        public function functionParamsTest(paramDynamic:*, paramString:String, paramNoType)
        {
            if(this[paramNoType].bool == true)
            {
                this[paramNoType].bool = false;
                this[paramNoType].prop1.prop2 = "nothing";
            }

            if(this[paramString].bool == true)
            {
                this[paramString].bool = false;
                this[paramString].prop1.prop2 = "nothing";
            }

            if(this[paramDynamic].bool == true)
            {
                this[paramDynamic].bool = false;
                this[paramDynamic].prop1.prop2 = "nothing";
            }
        }
    }
}

expected result

class Issue
{
    public function new()
    {
        var paramNoType = "hello";
        if (Reflect.field(Reflect.field(this, Std.string(paramNoType)), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, Std.string(paramNoType)), "bool", false);
            Reflect.setField(Reflect.field(this, Std.string(paramNoType)).prop1, "prop2", "nothing");
        }
        
        var paramString : String = "hello";
        if (Reflect.field(Reflect.field(this, paramString), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, paramString), "bool", false);
            Reflect.setField(Reflect.field(this, paramString).prop1, "prop2", "nothing");
        }
        
        var paramDynamic : Dynamic = "hello";
        if (Reflect.field(Reflect.field(this, Std.string(paramDynamic)), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, Std.string(paramDynamic)), "bool", false);
            Reflect.setField(Reflect.field(this, Std.string(paramDynamic)).prop1, "prop2", "nothing");
        }
    }
    
    public function functionParamsTest(paramDynamic : Dynamic, paramString : String, paramNoType)
    {
        
        if (Reflect.field(Reflect.field(this, Std.string(paramNoType)), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, Std.string(paramNoType)), "bool", false);
            Reflect.setField(Reflect.field(this, Std.string(paramNoType)).prop1, "prop2", "nothing");
        }
        
        if (Reflect.field(Reflect.field(this, paramString), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, paramString), "bool", false);
            Reflect.setField(Reflect.field(this, paramString).prop1, "prop2", "nothing");
        }
        
        if (Reflect.field(Reflect.field(this, Std.string(paramDynamic)), "bool") == true)
        {
            Reflect.setField(Reflect.field(this, Std.string(paramDynamic)), "bool", false);
            Reflect.setField(Reflect.field(this, Std.string(paramDynamic)).prop1, "prop2", "nothing");
        }
    }
}

actual result

class Issue
{
    public function new()
    {
        var paramNoType = "hello";
        if (this[paramNoType].bool == true)
        {
            this[paramNoType].bool = false;
            this[paramNoType].prop1.prop2 = "nothing";
        }
        
        var paramString : String = "hello";
        if (Reflect.field(this, paramString).bool == true)
        {
            Reflect.setField(this, paramString, false).bool;
            Reflect.setField(this, paramString, "nothing").prop1.prop2;
        }
        
        var paramDynamic : Dynamic = "hello";
        if (Reflect.field(this, Std.string(paramDynamic)).bool == true)
        {
            Reflect.setField(this, Std.string(paramDynamic), false).bool;
            Reflect.setField(this, Std.string(paramDynamic), "nothing").prop1.prop2;
        }
    }
    
    public function functionParamsTest(paramDynamic : Dynamic, paramString : String, paramNoType)
    {
        if (this[paramNoType].bool == true)
        {
            this[paramNoType].bool = false;
            this[paramNoType].prop1.prop2 = "nothing";
        }
        
        if (Reflect.field(this, paramString).bool == true)
        {
            Reflect.setField(this, paramString, false).bool;
            Reflect.setField(this, paramString, "nothing").prop1.prop2;
        }
        
        if (Reflect.field(this, Std.string(paramDynamic)).bool == true)
        {
            Reflect.setField(this, Std.string(paramDynamic), false).bool;
            Reflect.setField(this, Std.string(paramDynamic), "nothing").prop1.prop2;
        }
    }
}

mastef avatar Nov 02 '17 08:11 mastef