]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't transform an explicit "null" into a valid format-string
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 6 Dec 2017 15:11:10 +0000 (16:11 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 9 Dec 2017 13:34:50 +0000 (14:34 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=791215

tests/Makefile.am
tests/methods/bug791215.vala [new file with mode: 0644]
vala/valamethodcall.vala

index 8befbd161cd78df356ecdccf9b00f05f503d28a1..5a42d51b47e8848200841aa0f0be43d3e34a5487 100644 (file)
@@ -77,6 +77,7 @@ TESTS = \
        methods/bug737222.vala \
        methods/bug743877.vala \
        methods/bug771964.vala \
+       methods/bug791215.vala \
        methods/generics.vala \
        control-flow/break.vala \
        control-flow/expressions-conditional.vala \
diff --git a/tests/methods/bug791215.vala b/tests/methods/bug791215.vala
new file mode 100644 (file)
index 0000000..b5e0c09
--- /dev/null
@@ -0,0 +1,8 @@
+[PrintfFormat]
+void foo_print (string? fmt, ...) {
+       assert (fmt == null);
+}
+
+void main () {
+       foo_print (null);
+}
index 720b81cf46d61530d6adfeda13d1087c402a7e3b..68b689bc910ba6d7da89484198449aa728da44ae 100644 (file)
@@ -420,7 +420,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 = last_arg as StringLiteral;
                                if (format_literal == null && args.size == params.size - 1) {