Skip to content

Commit

Permalink
Fix: delay item 'id' validation to allow use of user-defined constants
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Aug 4, 2023
1 parent 59816db commit 5a5b481
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions nml/ast/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def __init__(self, params, body, pos):
if self.feature.value in (0x08, 0x0C, 0x0E):
raise generic.ScriptError("Defining item blocks for this feature is not allowed.", self.pos)
self.name = params[1] if len(params) >= 2 else None

self.id = params[2].reduce_constant(global_constants.const_list) if len(params) >= 3 else None
if isinstance(self.id, expression.ConstantNumeric) and self.id.value == -1:
self.id = None # id == -1 means default
self.id = params[2] if len(params) >= 3 else None

if len(params) >= 4:
if self.feature.value != 0x07:
Expand All @@ -66,6 +63,11 @@ def __init__(self, params, body, pos):
self.size = None

def register_names(self):
if self.id is not None:
self.id = self.id.reduce_constant(global_constants.const_list)
if isinstance(self.id, expression.ConstantNumeric) and self.id.value == -1:
self.id = None # id == -1 means default

if self.name:
if not isinstance(self.name, expression.Identifier):
raise generic.ScriptError("Item parameter 2 'name' should be an identifier", self.pos)
Expand Down

0 comments on commit 5a5b481

Please sign in to comment.