diff --git a/blueprintcompiler/language/contexts.py b/blueprintcompiler/language/contexts.py index 6e26048..9376211 100644 --- a/blueprintcompiler/language/contexts.py +++ b/blueprintcompiler/language/contexts.py @@ -60,19 +60,21 @@ class ScopeCtx: passed = {} for obj in self._iter_recursive(self.node): - if obj.tokens["id"] is None: + from .gtk_menu import Menu + + if not (isinstance(obj, Object) or isinstance(obj, Menu)) or obj.id is None: continue - if obj.tokens["id"] in passed: + if obj.id in passed: token = obj.group.tokens["id"] if not isinstance(obj, Template) and not isinstance( obj, ExtListItemFactory ): raise CompileError( - f"Duplicate object ID '{obj.tokens['id']}'", + f"Duplicate object ID '{obj.id}'", token.range, ) - passed[obj.tokens["id"]] = obj + passed[obj.id] = obj def _iter_recursive(self, node: AstNode): yield node diff --git a/tests/samples/issue_195.blp b/tests/samples/issue_195.blp new file mode 100644 index 0000000..50b5b95 --- /dev/null +++ b/tests/samples/issue_195.blp @@ -0,0 +1,11 @@ +using Gtk 4.0; +using Adw 1; + +Adw.AlertDialog dialog1 { + responses [ + ok: "Ok", + cancel: "Cancel", + ] +} + +Button cancel {} diff --git a/tests/samples/issue_195.ui b/tests/samples/issue_195.ui new file mode 100644 index 0000000..b57a379 --- /dev/null +++ b/tests/samples/issue_195.ui @@ -0,0 +1,16 @@ + + + + + + + Ok + Cancel + + + + \ No newline at end of file