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

Fix: Nicer error message when a station switch returns a SpriteLayout #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions nml/actions/action2var.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from nml import expression, generic, global_constants, nmlop
from nml.actions import action2, action2real, action2var_variables, action4, action6, actionD
from nml.ast import switch
from nml.ast import general, switch, spriteblock

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
nml.ast.spriteblock
begins an import cycle.
Import of module
nml.ast.switch
begins an import cycle.


class Action2Var(action2.Action2):
Expand Down Expand Up @@ -1016,6 +1016,16 @@
if result.name.value == "CB_FAILED":
return get_failed_cb_result(parent_action.feature, action_list, parent_action, result.pos)

target = action2.resolve_spritegroup(result.name) if not result.act2 else None

if parent_action.feature not in action2.features_sprite_layout and isinstance(target, spriteblock.SpriteLayout):
raise generic.ScriptError(
"SpriteLayout '{}' is not a valid return value for feature '{}'".format(
result.name, general.feature_name(parent_action.feature)
),
result.pos,
)

if len(result.param_list) == 0:
action2.add_ref(result, parent_action)
return result
Expand All @@ -1024,14 +1034,13 @@
# Insert an intermediate varaction2 to store expressions in registers
var_scope = get_scope(parent_action.feature, var_range)
varact2parser = Varaction2Parser(parent_action.feature, var_range)
layout = action2.resolve_spritegroup(result.name)
for i, param in enumerate(result.param_list):
if i > 0:
varact2parser.var_list.append(nmlop.VAL2)
varact2parser.var_list_size += 1
varact2parser.parse_expr(reduce_varaction2_expr(param, var_scope))
varact2parser.var_list.append(nmlop.STO_TMP)
store_tmp = VarAction2StoreCallParam(layout.register_map[parent_action.feature][i])
store_tmp = VarAction2StoreCallParam(target.register_map[parent_action.feature][i])
varact2parser.var_list.append(store_tmp)
varact2parser.var_list_size += store_tmp.get_size() + 1 # Add 1 for operator

Expand Down
Loading