]> 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>
Thu, 18 Mar 2021 09:10:01 +0000 (10:10 +0100)
tests/Makefile.am
tests/semantic/conditional-expression-incompatible.test [new file with mode: 0644]
vala/valaconditionalexpression.vala

index 6b77ef90d0f4b2654332037c4a7fd471b95215ec..3028a638e480f69c0240e543813634fe6afece7a 100644 (file)
@@ -917,6 +917,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..de1ffc83a351c0bb83260fa2d92b44f2f22a73ee 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'".printf (true_expression.value_type.to_prototype_string (), false_expression.value_type.to_prototype_string ()));
                        return false;
                }