values: Don't allow assigning true/false to object

Fix a bug in the type checking code where it would not produce an error
if you assigned "true" or "false" to an object property.
This commit is contained in:
James Westman 2025-01-05 15:34:16 -06:00
parent 1e9b01bab9
commit 866092ccf7
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
3 changed files with 14 additions and 1 deletions

View file

@ -338,7 +338,14 @@ class IdentLiteral(AstNode):
raise CompileError(
'"item" can only be used in an expression literal'
)
elif self.ident not in ["true", "false"]:
elif self.ident in ["true", "false"]:
if expected_type is not None and not isinstance(
expected_type, gir.BoolType
):
raise CompileError(
f"Cannot assign boolean to {expected_type.full_name}"
)
else:
raise CompileError(
f"Could not find object with ID {self.ident}",
did_you_mean=(

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Button {
child: false;
}

View file

@ -0,0 +1 @@
4,10,5,Cannot assign boolean to Gtk.Widget