[vala/staging] codegen: Properly compare string if binary-expression contains string-literal
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Properly compare string if binary-expression contains string-literal
- Date: Sat, 11 Jul 2020 17:07:03 +0000 (UTC)
commit 8f9f2f1dd29de5e2b4462c18c7f397038fce0025
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jul 11 18:29:42 2020 +0200
codegen: Properly compare string if binary-expression contains string-literal
Found by -Werror=address
codegen/valaccodebasemodule.vala | 9 +++++----
tests/Makefile.am | 1 +
tests/generics/string-literal-comparison.vala | 10 ++++++++++
3 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a159ecfcf..5d70d5b49 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5569,10 +5569,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- if (!(expr.left.value_type is NullType)
- && expr.left.value_type.compatible (string_type)
- && !(expr.right.value_type is NullType)
- && expr.right.value_type.compatible (string_type)) {
+ bool is_string_comparison = !(expr.left.value_type is NullType) &&
expr.left.value_type.compatible (string_type)
+ && !(expr.right.value_type is NullType) && expr.right.value_type.compatible
(string_type);
+ bool has_string_literal = (expr.left is StringLiteral || expr.right is StringLiteral);
+
+ if (is_string_comparison || (has_string_literal && expr.operator != BinaryOperator.PLUS)) {
switch (expr.operator) {
case BinaryOperator.PLUS:
// string concatenation
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3867108ca..9980e94bb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -594,6 +594,7 @@ TESTS = \
generics/integer-type-cast.vala \
generics/parameter-sizeof-initializer.vala \
generics/member-dup-destroy.vala \
+ generics/string-literal-comparison.vala \
generics/type-parameter-properties.vala \
generics/bug640330.test \
generics/bug640330.vala \
diff --git a/tests/generics/string-literal-comparison.vala b/tests/generics/string-literal-comparison.vala
new file mode 100644
index 000000000..b1e6c2e9a
--- /dev/null
+++ b/tests/generics/string-literal-comparison.vala
@@ -0,0 +1,10 @@
+class Foo<G> {
+ public Foo (G g) {
+ assert (g == "foo");
+ }
+}
+
+void main () {
+ var s = "foo";
+ var foo = new Foo<string> (s);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]