mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
parent
0a0389b1f8
commit
664fa2250b
4 changed files with 27 additions and 0 deletions
|
@ -24,6 +24,10 @@ from .gobject_object import Object
|
||||||
from .response_id import ResponseId
|
from .response_id import ResponseId
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
|
ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [
|
||||||
|
("Gtk", "Buildable"),
|
||||||
|
("Gio", "ListStore")
|
||||||
|
]
|
||||||
|
|
||||||
class Child(AstNode):
|
class Child(AstNode):
|
||||||
grammar = [
|
grammar = [
|
||||||
|
@ -37,6 +41,22 @@ class Child(AstNode):
|
||||||
Object,
|
Object,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@validate()
|
||||||
|
def parent_can_have_child(self):
|
||||||
|
if gir_class := self.parent.gir_class:
|
||||||
|
for namespace, name in ALLOWED_PARENTS:
|
||||||
|
parent_type = self.root.gir.get_type(name, namespace)
|
||||||
|
if gir_class.assignable_to(parent_type):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
hints=["only Gio.ListStore or Gtk.Buildable implementors can have children"]
|
||||||
|
if "child" in gir_class.properties:
|
||||||
|
hints.append("did you mean to assign this object to the 'child' property?")
|
||||||
|
raise CompileError(
|
||||||
|
f"{gir_class.full_name} doesn't have children",
|
||||||
|
hints=hints,
|
||||||
|
)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def response_id(self) -> T.Optional[ResponseId]:
|
def response_id(self) -> T.Optional[ResponseId]:
|
||||||
"""Get action widget's response ID.
|
"""Get action widget's response ID.
|
||||||
|
|
5
tests/sample_errors/children.blp
Normal file
5
tests/sample_errors/children.blp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
ListItem {
|
||||||
|
Label {}
|
||||||
|
}
|
1
tests/sample_errors/children.err
Normal file
1
tests/sample_errors/children.err
Normal file
|
@ -0,0 +1 @@
|
||||||
|
4,3,8,Gtk.ListItem doesn't have children
|
|
@ -175,6 +175,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample_error("action_widget_response_dne")
|
self.assert_sample_error("action_widget_response_dne")
|
||||||
self.assert_sample_error("action_widget_negative_response")
|
self.assert_sample_error("action_widget_negative_response")
|
||||||
self.assert_sample_error("bitfield_member_dne")
|
self.assert_sample_error("bitfield_member_dne")
|
||||||
|
self.assert_sample_error("children")
|
||||||
self.assert_sample_error("class_assign")
|
self.assert_sample_error("class_assign")
|
||||||
self.assert_sample_error("class_dne")
|
self.assert_sample_error("class_dne")
|
||||||
self.assert_sample_error("consecutive_unexpected_tokens")
|
self.assert_sample_error("consecutive_unexpected_tokens")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue