]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Consider boolean types are compatible with each other
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 1 Apr 2020 12:02:55 +0000 (14:02 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 20 Apr 2020 19:18:32 +0000 (21:18 +0200)
tests/Makefile.am
tests/basic-types/boolean.vala [new file with mode: 0644]
tests/basic-types/custom-types.vala
vala/valadatatype.vala

index 847151d1d2711458ea84c0f3097916b7a2c4e6b9..f97991e90e6700f37f257a9a8d2b82147348ac49 100644 (file)
@@ -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 (file)
index 0000000..1e6c04f
--- /dev/null
@@ -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);
+       }
+}
index d979a9beb1a9cbb99155d6ec1a42c2f96e109d05..e8aa5d727928b3f7ce5107495df82f6d66095f39 100644 (file)
@@ -46,6 +46,7 @@ void main () {
                assert (baz == double.MAX);
        }
        {
-               manam_t manam;
+               manam_t manam = true;
+               assert (manam);
        }
 }
index cda1ba5e08a814cc5db2093aeae1d0aac116b3df..a46eedd339181cb7de62d9dcee68db0fa6b316b6 100644 (file)
@@ -355,6 +355,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;