Cannot read property 'formals' of null

I’m playing sarven-brawl and I’m running into a code error.

    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if is_soldier(enemy):
        # Assess the threat and take appropriate action

The if line is giving the error Cannot read property 'formals' of null when is_soldier(enemy) is evaluated and enemy is None (or null to be precise).

I’m performing the null check inside is_soldier() but it’s never reached because the program crashes before reaching the check.

FWIW, here is my definition of is_soldier(). It shouldn’t matter how it’s defined since I believe passing null as an argument is causing the error.

def is_soldier(enemy):
    if enemy and not is_sandyak(enemy):
        return True
    return False

That is weird. The simple fix would be to check null status outside the function:

if enemy and is_soldier(enemy):

But, no idea why you would need to do that instead of just passing enemy into the function.

Interesting, probably hitting some new corner case in the Python transpilation process. I’ve opened a bug here (which may get moved):