diff --git a/blueprintcompiler/language/gobject_object.py b/blueprintcompiler/language/gobject_object.py index 1dbbce5..9eeae3d 100644 --- a/blueprintcompiler/language/gobject_object.py +++ b/blueprintcompiler/language/gobject_object.py @@ -26,6 +26,9 @@ from .response_id import ExtResponse from .types import ClassName, ConcreteClassName +RESERVED_IDS = {"this", "self", "template", "true", "false", "null", "none"} + + class ObjectContent(AstNode): grammar = ["{", Until(OBJECT_CONTENT_HOOKS, "}")] @@ -73,6 +76,11 @@ class Object(AstNode): if child.response_id ] + @validate("id") + def object_id_not_reserved(self): + if self.id in RESERVED_IDS: + raise CompileWarning(f"{self.id} may be a confusing object ID") + def validate_parent_type(node, ns: str, name: str, err_msg: str): parent = node.root.gir.get_type(name, ns) diff --git a/blueprintcompiler/language/gtk_menu.py b/blueprintcompiler/language/gtk_menu.py index 707b072..b9de906 100644 --- a/blueprintcompiler/language/gtk_menu.py +++ b/blueprintcompiler/language/gtk_menu.py @@ -23,6 +23,7 @@ from blueprintcompiler.language.values import StringValue from .common import * from .contexts import ValueTypeCtx +from .gobject_object import RESERVED_IDS class Menu(AstNode): @@ -47,6 +48,11 @@ class Menu(AstNode): if self.tokens["tag"] == "menu" and self.tokens["id"] is None: raise CompileError("Menu requires an ID") + @validate("id") + def object_id_not_reserved(self): + if self.id in RESERVED_IDS: + raise CompileWarning(f"{self.id} may be a confusing object ID") + class MenuAttribute(AstNode): tag_name = "attribute"