diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index 70d8e89..a9f5693 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -126,6 +126,22 @@ class UncheckedType(GirType): return self._name +class ArrayType(GirType): + def __init__(self, inner: GirType) -> None: + self._inner = inner + + def assignable_to(self, other: GirType) -> bool: + return isinstance(other, ArrayType) and self._inner.assignable_to(other._inner) + + @property + def name(self) -> str: + return self._inner.name + "[]" + + @property + def full_name(self) -> str: + return self._inner.full_name + "[]" + + class BasicType(GirType): name: str = "unknown type" @@ -714,9 +730,15 @@ class Repository(GirNode): else: raise CompilerBugError("Unknown type ID", type_id) else: - return self._resolve_dir_entry( - self.tl.header[type_id].INTERFACE_TYPE_INTERFACE - ) + blob = self.tl.header[type_id] + if blob.TYPE_BLOB_TAG == typelib.TYPE_INTERFACE: + return self._resolve_dir_entry( + self.tl.header[type_id].TYPE_BLOB_INTERFACE + ) + elif blob.TYPE_BLOB_TAG == typelib.TYPE_ARRAY: + return ArrayType(self._resolve_type_id(blob.TYPE_BLOB_ARRAY_INNER)) + else: + raise CompilerBugError(f"{blob.TYPE_BLOB_TAG}") class GirContext: diff --git a/blueprintcompiler/typelib.py b/blueprintcompiler/typelib.py index 48ec416..6babc10 100644 --- a/blueprintcompiler/typelib.py +++ b/blueprintcompiler/typelib.py @@ -136,7 +136,9 @@ class Typelib: ATTR_NAME = Field(0x0, "string") ATTR_VALUE = Field(0x0, "string") - INTERFACE_TYPE_INTERFACE = Field(0x2, "dir_entry") + TYPE_BLOB_TAG = Field(0x0, "u8", 3, 5) + TYPE_BLOB_INTERFACE = Field(0x2, "dir_entry") + TYPE_BLOB_ARRAY_INNER = Field(0x4, "u32") BLOB_NAME = Field(0x4, "string") diff --git a/tests/sample_errors/strv.blp b/tests/sample_errors/strv.blp new file mode 100644 index 0000000..2f4983a --- /dev/null +++ b/tests/sample_errors/strv.blp @@ -0,0 +1,6 @@ +using Gtk 4.0; +using Adw 1; + +Adw.AboutWindow { + developers: Gtk.StringList {}; +} \ No newline at end of file diff --git a/tests/sample_errors/strv.err b/tests/sample_errors/strv.err new file mode 100644 index 0000000..f0d6961 --- /dev/null +++ b/tests/sample_errors/strv.err @@ -0,0 +1 @@ +5,15,17,Cannot assign Gtk.StringList to string[] \ No newline at end of file diff --git a/tests/test_samples.py b/tests/test_samples.py index c5caca5..7bc7d28 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -231,6 +231,7 @@ class TestSamples(unittest.TestCase): self.assert_sample_error("signal_object_dne") self.assert_sample_error("size_group_non_widget") self.assert_sample_error("size_group_obj_dne") + self.assert_sample_error("strv") self.assert_sample_error("styles_in_non_widget") self.assert_sample_error("two_templates") self.assert_sample_error("uint")