[vala] Fix arithmetic expressions whose operands have different types
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix arithmetic expressions whose operands have different types
- Date: Tue, 5 Jul 2011 18:47:55 +0000 (UTC)
commit f70d37bd3099b8bb422ffe57e9d6b6c7415feeb7
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jul 5 20:24:51 2011 +0200
Fix arithmetic expressions whose operands have different types
tests/basic-types/floats.vala | 4 ++++
vala/valabinaryexpression.vala | 19 ++++++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/tests/basic-types/floats.vala b/tests/basic-types/floats.vala
index 3294bb9..3f6eaa1 100644
--- a/tests/basic-types/floats.vala
+++ b/tests/basic-types/floats.vala
@@ -52,6 +52,10 @@ void test_double () {
d = double.MAX;
assert (d == double.MAX);
assert (d > double.MIN);
+
+ // nullable
+ double? d2 = 10;
+ assert (d2 == 10);
}
void main () {
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 2cddc2f..50d4948 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -364,9 +364,6 @@ public class Vala.BinaryExpression : Expression {
} else {
DataType resulting_type;
- left.target_type.nullable = false;
- right.target_type.nullable = false;
-
if (chained) {
var lbe = (BinaryExpression) left;
resulting_type = context.analyzer.get_arithmetic_result_type (lbe.right.target_type, right.target_type);
@@ -379,6 +376,13 @@ public class Vala.BinaryExpression : Expression {
Report.error (source_reference, "Relational operation not supported for types `%s' and `%s'".printf (left.value_type.to_string (), right.value_type.to_string ()));
return false;
}
+
+ if (!chained) {
+ left.target_type = resulting_type.copy ();
+ }
+ right.target_type = resulting_type.copy ();
+ left.target_type.nullable = false;
+ right.target_type.nullable = false;
}
value_type = context.analyzer.bool_type;
@@ -393,9 +397,14 @@ public class Vala.BinaryExpression : Expression {
return false;
}
- left.target_type = left.value_type.copy ();
+ var resulting_type = context.analyzer.get_arithmetic_result_type (left.target_type, right.target_type);
+ if (resulting_type != null) {
+ // numeric operation
+ left.target_type = resulting_type.copy ();
+ right.target_type = resulting_type.copy ();
+ }
+
left.target_type.value_owned = false;
- right.target_type = right.value_type.copy ();
right.target_type.value_owned = false;
if (left.value_type.nullable != right.value_type.nullable) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]