[vala/staging] vala: Improve error for incompatible expressions in conditional expression
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Improve error for incompatible expressions in conditional expression
- Date: Sun, 14 Mar 2021 11:49:42 +0000 (UTC)
commit c6142ef5261617095aa06f431bab92f147f53a37
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 3373316ed..bfbc13dd3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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..c8bfdbce1 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'",
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]