[vala/0.36: 102/212] vala: Don't transform an explicit "null" into a valid format-string



commit 49265d1bbc2c70d6bd0105a3120747623538666b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Dec 6 16:11:10 2017 +0100

    vala: Don't transform an explicit "null" into a valid format-string
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791215

 tests/Makefile.am                      |    1 +
 tests/methods/bug791215.vala           |    8 ++++++++
 vala/valamethodcall.vala               |    4 +++-
 vala/valaobjectcreationexpression.vala |    4 +++-
 4 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9240423..38a78f7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -96,6 +96,7 @@ TESTS = \
        methods/bug774060.vala \
        methods/bug775466.test \
        methods/bug781061.vala \
+       methods/bug791215.vala \
        methods/generics.vala \
        methods/printf-invalid.test \
        methods/printf-constructor.vala \
diff --git a/tests/methods/bug791215.vala b/tests/methods/bug791215.vala
new file mode 100644
index 0000000..b5e0c09
--- /dev/null
+++ b/tests/methods/bug791215.vala
@@ -0,0 +1,8 @@
+[PrintfFormat]
+void foo_print (string? fmt, ...) {
+       assert (fmt == null);
+}
+
+void main () {
+       foo_print (null);
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 444395a..76f2403 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -412,7 +412,9 @@ public class Vala.MethodCall : Expression {
                // printf arguments
                if (mtype is MethodType && ((MethodType) mtype).method_symbol.printf_format) {
                        StringLiteral format_literal = null;
-                       if (last_arg != null) {
+                       if (last_arg is NullLiteral) {
+                               // do not replace explicit null
+                       } else if (last_arg != null) {
                                // use last argument as format string
                                format_literal = StringLiteral.get_format_literal (last_arg);
                                if (format_literal == null && args.size == params.size - 1) {
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 4e5a9b9..e203a1a 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -385,7 +385,9 @@ public class Vala.ObjectCreationExpression : Expression {
                        // printf arguments
                        if (m.printf_format) {
                                StringLiteral format_literal = null;
-                               if (last_arg != null) {
+                               if (last_arg is NullLiteral) {
+                                       // do not replace explicit null
+                               } else if (last_arg != null) {
                                        // use last argument as format string
                                        format_literal = StringLiteral.get_format_literal (last_arg);
                                        if (format_literal == null && args.size == m.get_parameters ().size - 
1) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]