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: Register named parameters earlier #301

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
22 changes: 13 additions & 9 deletions nml/actions/actionD.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,9 @@ def __init__(self, param, value):
self.param = param
self.value = value

def pre_process(self):
self.value = self.value.reduce(global_constants.const_list)

def register_names(self):
self.param = self.param.reduce(global_constants.const_list, unknown_id_fatal=False)
if isinstance(self.param, expression.SpecialParameter):
if not self.param.can_assign():
raise generic.ScriptError(
"Trying to assign a value to the read-only variable '{}'".format(self.param.name), self.param.pos
)
elif isinstance(self.param, expression.Identifier):
if isinstance(self.param, expression.Identifier):
if global_constants.identifier_refcount[self.param.value] == 0:
generic.print_warning(
generic.Warning.OPTIMISATION,
Expand All @@ -110,6 +103,17 @@ def pre_process(self):
return
num = action6.free_parameters.pop_unique(self.pos)
global_constants.named_parameters[self.param.value] = num

def pre_process(self):
self.value = self.value.reduce(global_constants.const_list)

if isinstance(self.param, expression.SpecialParameter):
if not self.param.can_assign():
raise generic.ScriptError(
"Trying to assign a value to the read-only variable '{}'".format(self.param.name), self.param.pos
)
elif isinstance(self.param, expression.Identifier):
return
elif not isinstance(self.param, expression.Parameter):
raise generic.ScriptError("Left side of an assignment must be a parameter.", self.param.pos)

Expand Down