validation: Writable/construct-only properties

Add two new errors, one for non-writable properties and another for
binding construct-only properties.
This commit is contained in:
James Westman 2022-04-28 22:42:09 -05:00
parent 3b39e0d541
commit f78478bea1
5 changed files with 31 additions and 1 deletions

View file

@ -184,6 +184,14 @@ class Property(GirNode):
def signature(self):
return f"{self.type_name} {self.container.name}.{self.name}"
@property
def writable(self):
return self.xml["writable"] == "1"
@property
def construct_only(self):
return self.xml["construct-only"] == "1"
class Parameter(GirNode):
def __init__(self, container: GirNode, xml: xml_reader.Element):

View file

@ -29,7 +29,7 @@ class Property(AstNode):
Statement(
UseIdent("name"),
":",
"bind",
Keyword("bind"),
UseIdent("bind_source").expected("the ID of a source object to bind from"),
".",
UseIdent("bind_property").expected("a property name to bind from"),
@ -85,6 +85,19 @@ class Property(AstNode):
did_you_mean=(self.tokens["name"], self.gir_class.properties.keys())
)
@validate("bind")
def property_bindable(self):
if self.tokens["bind"] and self.gir_property is not None and self.gir_property.construct_only:
raise CompileError(
f"{self.gir_property.full_name} can't be bound because it is construct-only",
hints=["construct-only properties may only be set to a static value"]
)
@validate("name")
def property_writable(self):
if self.gir_property is not None and not self.gir_property.writable:
raise CompileError(f"{self.gir_property.full_name} is not writable")
@validate()
def obj_property_type(self):