[vala/0.50] vala: Improve error for incompatible expressions in conditional expression
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.50] vala: Improve error for incompatible expressions in conditional expression
- Date: Thu, 18 Mar 2021 09:35:02 +0000 (UTC)
commit f42a3e88a5ab9c10c4a2bf93a1c52c3c45bd5940
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Mar 14 12:38:16 2021 +0100
vala: Improve error for incompatible expressions in conditional expression
tests/Makefile.am | 1 +
tests/semantic/conditional-expression-incompatible.test | 7 +++++++
vala/valaconditionalexpression.vala | 3 ++-
3 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6b77ef90d..3028a638e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..1d8c108c3
--- /dev/null
+++ b/tests/semantic/conditional-expression-incompatible.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void main () {
+ string foo = "foo";
+ int bar = 42;
+ var manam = true ? foo : bar;
+}
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 1bc100081..de1ffc83a 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]