]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Improve error for incompatible expressions in conditional expression
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 14 Mar 2021 11:38:16 +0000 (12:38 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 14 Mar 2021 11:45:41 +0000 (12:45 +0100)
tests/Makefile.am
tests/semantic/conditional-expression-incompatible.test [new file with mode: 0644]
vala/valaconditionalexpression.vala

index 3373316edd3d222447a05a7c3eb608a2532d54de..bfbc13dd303f89f8e7bb4baea0c4ff9430e6649a 100644 (file)
@@ -934,6 +934,7 @@ TESTS = \
        semantic/class-singleton-non-gobject.test \
        semantic/class-too-few-type-arguments.test \
        semantic/class-too-many-type-arguments.test \
+       semantic/conditional-expression-incompatible.test \
        semantic/conditional-expression-no-block.test \
        semantic/constant-extern.test \
        semantic/constant-pointer.test \
diff --git a/tests/semantic/conditional-expression-incompatible.test b/tests/semantic/conditional-expression-incompatible.test
new file mode 100644 (file)
index 0000000..1d8c108
--- /dev/null
@@ -0,0 +1,7 @@
+Invalid Code
+
+void main () {
+       string foo = "foo";
+       int bar = 42;
+       var manam = true ? foo : bar;
+}
index 1bc100081046d627ba9e5403c85ab9e7ca38b1fb..c8bfdbce135d1640f8181887d9c040202e333f5d 100644 (file)
@@ -194,7 +194,8 @@ public class Vala.ConditionalExpression : Expression {
                        value_type = false_expression.value_type.copy ();
                } else {
                        error = true;
-                       Report.error (condition.source_reference, "Incompatible expressions");
+                       var source_reference = new SourceReference (true_expression.source_reference.file, true_expression.source_reference.begin, false_expression.source_reference.end);
+                       Report.error (source_reference, "Cannot resolve target type from `%s' and `%s'", true_expression.value_type.to_prototype_string (), false_expression.value_type.to_prototype_string ());
                        return false;
                }