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

Detecting duplicated components #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions trlc/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,9 @@ def to_python_dict(self):
"""
return {name: value.to_python_object()
for name, value in self.field.items()}

def is_component_implicit_null(self, component) -> bool:
return not isinstance(self.field[component.name], Implicit_Null)

def assign(self, component, value):
assert isinstance(component, Composite_Component)
Expand All @@ -3008,6 +3011,8 @@ def assign(self, component, value):
Implicit_Null,
Unary_Expression)), \
"value is %s" % value.__class__.__name__
if self.is_component_implicit_null(component):
raise KeyError(f"Component {component.name} already assigned to {self.n_typ.name} {self.name}!")
self.field[component.name] = value

def dump(self, indent=0): # pragma: no cover
Expand Down
5 changes: 5 additions & 0 deletions trlc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,11 @@ def parse_record_object_declaration(self):
comp = r_typ.components.lookup(self.mh,
self.ct,
ast.Composite_Component)
if obj.is_component_implicit_null(comp):
self.mh.error(self.ct.location,
"component '%s' already assigned at line %i" %
(comp.name,
obj.field[comp.name].location.line_no))
comp.set_ast_link(self.ct)
if r_typ.is_frozen(comp):
self.mh.error(self.ct.location,
Expand Down
Loading