report warning when using null literal as argument for non-null parameter
authorJuerg Billeter <j@bitron.ch>
Mon, 14 Apr 2008 19:54:28 +0000 (19:54 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 14 Apr 2008 19:54:28 +0000 (19:54 +0000)
2008-04-14  Juerg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala: report warning when using null
  literal as argument for non-null parameter

* vapi/glib-2.0.vapi: fix warnings

svn path=/trunk/; revision=1229

ChangeLog
vala/valasemanticanalyzer.vala
vapi/glib-2.0.vapi

index 28dc4a0..0bf97f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
 2008-04-14  Jürg Billeter  <j@bitron.ch>
 
        * vala/valasemanticanalyzer.vala: report warning when using null
+         literal as argument for non-null parameter
+
+       * vapi/glib-2.0.vapi: fix warnings
+
+2008-04-14  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valasemanticanalyzer.vala: report warning when using null
          literal as return expression of method returning non-null value
 
        * */*.vala: fix warnings
index 5921b31..1c00005 100644 (file)
@@ -1822,12 +1822,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        // disallow untyped arguments except for type inference of callbacks
                                        if (!(param.type_reference is DelegateType) || !(arg.symbol_reference is Method)) {
                                                expr.error = true;
-                                               Report.error (expr.source_reference, "Invalid type for argument %d".printf (i + 1));
+                                               Report.error (arg.source_reference, "Invalid type for argument %d".printf (i + 1));
                                                return false;
                                        }
                                } else if (!arg.static_type.compatible (param.type_reference)) {
                                        expr.error = true;
-                                       Report.error (expr.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.to_string (), param.type_reference.to_string ()));
+                                       Report.error (arg.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.to_string (), param.type_reference.to_string ()));
                                        return false;
                                } else {
                                        // 0 => null, 1 => in, 2 => ref, 3 => out
@@ -1846,25 +1846,27 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        if (arg_type == 0) {
                                                if (param.type_reference.is_ref) {
                                                        expr.error = true;
-                                                       Report.error (expr.source_reference, "Argument %d: Cannot pass null to reference parameter".printf (i + 1));
+                                                       Report.error (arg.source_reference, "Argument %d: Cannot pass null to reference parameter".printf (i + 1));
                                                        return false;
+                                               } else if (!param.type_reference.is_out && !param.type_reference.nullable) {
+                                                       Report.warning (arg.source_reference, "Argument %d: Cannot pass null to non-null parameter type".printf (i + 1));
                                                }
                                        } else if (arg_type == 1) {
                                                if (param.type_reference.is_ref || param.type_reference.is_out) {
                                                        expr.error = true;
-                                                       Report.error (expr.source_reference, "Argument %d: Cannot pass value to reference or output parameter".printf (i + 1));
+                                                       Report.error (arg.source_reference, "Argument %d: Cannot pass value to reference or output parameter".printf (i + 1));
                                                        return false;
                                                }
                                        } else if (arg_type == 2) {
                                                if (!param.type_reference.is_ref) {
                                                        expr.error = true;
-                                                       Report.error (expr.source_reference, "Argument %d: Cannot pass ref argument to non-reference parameter".printf (i + 1));
+                                                       Report.error (arg.source_reference, "Argument %d: Cannot pass ref argument to non-reference parameter".printf (i + 1));
                                                        return false;
                                                }
                                        } else if (arg_type == 3) {
                                                if (!param.type_reference.is_out) {
                                                        expr.error = true;
-                                                       Report.error (expr.source_reference, "Argument %d: Cannot pass out argument to non-output parameter".printf (i + 1));
+                                                       Report.error (arg.source_reference, "Argument %d: Cannot pass out argument to non-output parameter".printf (i + 1));
                                                        return false;
                                                }
                                        }
index 5234773..858f69f 100644 (file)
@@ -429,7 +429,7 @@ public struct unichar {
        public UnicodeType type ();
        public UnicodeBreakType break_type ();
 
-       public int to_utf8 (string outbuf);
+       public int to_utf8 (string? outbuf);
 }
 
 [CCode (cprefix = "G_UNICODE_")]
@@ -2193,7 +2193,7 @@ namespace GLib {
                public bool get_ignore_unknown_options ();
                public string get_help (bool main_help, OptionGroup group);
                [NoArrayLength]
-               public void add_main_entries (OptionEntry[] entries, string translation_domain);
+               public void add_main_entries (OptionEntry[] entries, string? translation_domain);
                public void add_group (OptionGroup# group);
                public void set_main_group (OptionGroup# group);
                public weak OptionGroup get_main_group ();