[vala/0.48] vala: Consider boolean types are compatible with each other



commit 30427cf36b2605b75b099ffc01f8453742c71aa2
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Apr 1 14:02:55 2020 +0200

    vala: Consider boolean types are compatible with each other

 tests/Makefile.am                   |  1 +
 tests/basic-types/boolean.vala      | 20 ++++++++++++++++++++
 tests/basic-types/custom-types.vala |  3 ++-
 vala/valadatatype.vala              |  4 ++++
 4 files changed, 27 insertions(+), 1 deletion(-)
---
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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]