From: Juerg Billeter Date: Mon, 14 Apr 2008 19:54:28 +0000 (+0000) Subject: report warning when using null literal as argument for non-null parameter X-Git-Tag: VALA_0_3_1~73 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=daa6b6e5d9d0e7d4259be35d108650477d73c45b;p=platform%2Fupstream%2Fvala.git report warning when using null literal as argument for non-null parameter 2008-04-14 Juerg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index 28dc4a0..0bf97f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ 2008-04-14 Jürg Billeter * 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 + + * vala/valasemanticanalyzer.vala: report warning when using null literal as return expression of method returning non-null value * */*.vala: fix warnings diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 5921b31..1c00005 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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; } } diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 5234773..858f69f 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -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 ();