Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Inline function name is redefined #8971

Closed
pbotsman opened this issue Nov 15, 2019 · 1 comment
Closed

[python] Inline function name is redefined #8971

pbotsman opened this issue Nov 15, 2019 · 1 comment
Milestone

Comments

@pbotsman
Copy link

@pbotsman pbotsman commented Nov 15, 2019

Haxe version: 4.0.2

The problem is that the function name _hx_local_0 gets redefined by the function with the same name, so the first function is not called anymore.

Haxe code:

var obj = {
  a: cast('asd', String),
  b: cast('dsa', String)
}

Python compiled code:

def _hx_local_0():
    _hx_local_2 = "asd"
    if (Std._hx_is(_hx_local_2,str) or ((_hx_local_2 is None))):
        _hx_local_2
    else:
        raise _HxException("Class cast error")
    return _hx_local_2
def _hx_local_0():
    _hx_local_3 = "dsa"
    if (Std._hx_is(_hx_local_3,str) or ((_hx_local_3 is None))):
        _hx_local_3
    else:
        raise _HxException("Class cast error")
    return _hx_local_3
obj1 = _hx_AnonObject({'a': _hx_local_0(), 'b': _hx_local_0()})

Looks like that the same problem is happening with other inline functions:
Haxe code:

var data: Array<Dynamic> = [{a: 1}, {a: 2}];
var filteredData = cast(data, Array<Dynamic>).filter(function(el) {
  return el.a == 1;
});

Python compiled code:

data = [_hx_AnonObject({'a': 1}), _hx_AnonObject({'a': 2})]
def _hx_local_0(el):
    return (el.a == 1)
def _hx_local_0():
    _hx_local_1 = data
    if (Std._hx_is(_hx_local_1,list) or ((_hx_local_1 is None))):
        _hx_local_1
    else:
        raise _HxException("Class cast error")
    return _hx_local_1
filteredData = list(filter(_hx_local_0,_hx_local_0()))

_hx_local_0 function is also redefined and passed to a filter

@Aurel300 Aurel300 added this to the Bugs milestone Nov 15, 2019
@Aurel300

This comment has been minimized.

Copy link
Contributor

@Aurel300 Aurel300 commented Nov 15, 2019

It seems this should be handled with counters, which are sometimes given to lift_expr in genpy, but usually not, resulting in a new counter being defined (starting from 0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.