From: Rico Tzschichholz Date: Wed, 1 Apr 2020 12:02:55 +0000 (+0200) Subject: vala: Consider boolean types are compatible with each other X-Git-Tag: 0.49.1~207 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2F792e9672a07fec8cbe4152789ad38c4304c8e266;p=thirdparty%2Fvala.git vala: Consider boolean types are compatible with each other --- diff --git a/tests/Makefile.am b/tests/Makefile.am index a77e4dbae..9f956d793 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,6 +24,7 @@ TESTS = \ basic-types/integers.vala \ basic-types/escape-chars.vala \ basic-types/floats.vala \ + basic-types/boolean.vala \ basic-types/custom-types.vala \ basic-types/default-gtype.vala \ basic-types/strings.vala \ diff --git a/tests/basic-types/boolean.vala b/tests/basic-types/boolean.vala new file mode 100644 index 000000000..1e6c04fb3 --- /dev/null +++ b/tests/basic-types/boolean.vala @@ -0,0 +1,20 @@ +[SimpleType] +[BooleanType] +public struct Foo { + public void check () { + if (this) { + return; + } + assert (true); + } +} + +void main () { + Foo foo = true; + + foo.check (); + + if (!foo) { + assert (true); + } +} diff --git a/tests/basic-types/custom-types.vala b/tests/basic-types/custom-types.vala index d979a9beb..e8aa5d727 100644 --- a/tests/basic-types/custom-types.vala +++ b/tests/basic-types/custom-types.vala @@ -46,6 +46,7 @@ void main () { assert (baz == double.MAX); } { - manam_t manam; + manam_t manam = true; + assert (manam); } } diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 7dd0e8dcb..37d04a1ed 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -366,6 +366,10 @@ public abstract class Vala.DataType : CodeNode { } } + if (expr_struct.is_boolean_type () && expect_struct.is_boolean_type ()) { + return true; + } + // Allow compatiblity of struct subtypes in both ways if (expect_struct.is_subtype_of (expr_struct)) { return true;