SkyTemple / ExplorerScript

ExplorerScript and SSBScript: Script languages for decompiled SSB (Pokémon Mystery Dungeon Explorers of Sky)
MIT License
16 stars 6 forks source link

KeyError caused by call or jump #19

Closed Frostbyte0x70 closed 1 year ago

Frostbyte0x70 commented 2 years ago

Originally reported at https://discord.com/channels/710190644152369162/1002325768682090636/1002330772272857239

The following code triggers a KeyError after compiling the script, deleting the original ExplorerScript source and trying to decompile it again:

def 0 {
    call @something;
    end;
    §something;
    return;
}

The call opcode can be replaced with a jump, both produce the same result.

The exception is raised at https://github.com/SkyTemple/ExplorerScript/blob/ca2502370eab78aba95e243225e17380b6413c9e/explorerscript/ssb_converting/decompiler/graph_building/graph_minimizer.py#L709, because label_indices is empty. The reason why it's empty is because no elements were added to it at https://github.com/SkyTemple/ExplorerScript/blob/ca2502370eab78aba95e243225e17380b6413c9e/explorerscript/ssb_converting/decompiler/graph_building/graph_minimizer.py#L54, since there weren't any SsbLabel in the list of opcodes.