Add warning for confusing object IDs

This commit is contained in:
James Westman 2023-05-08 10:19:19 -05:00
parent 77dc9350e9
commit 43fbf8cf8e
2 changed files with 14 additions and 0 deletions

View file

@ -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)