[vala/0.40] vala: Consider boolean types are compatible with each other
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] vala: Consider boolean types are compatible with each other
- Date: Tue, 21 Apr 2020 07:48:54 +0000 (UTC)
commit d06b4f6e3d379b85e9eef4adbe978a9b94497167
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 e80adc429..30777a735 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,6 +18,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 00cfca581..ca9d3a61a 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -341,6 +341,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]