[vala] Warn if a parameter without default follows a parameter with default value



commit b22255aa25e0296211ea7ca404970d1677747180
Author: Simon Werbeck <simon werbeck gmail com>
Date:   Sat Apr 6 08:51:19 2013 +0200

    Warn if a parameter without default follows a parameter with default value
    
    Fixes bug 644241.

 vala/valamethod.vala |    6 ++++++
 vapi/glib-2.0.vapi   |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 5e5f826..f1b7577 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -654,12 +654,18 @@ public class Vala.Method : Subroutine {
                        Report.error (parameters[0].source_reference, "Named parameter required before 
`...'");
                }
 
+               var optional_param = false;
                foreach (Parameter param in parameters) {
                        param.check (context);
                        if (coroutine && param.direction == ParameterDirection.REF) {
                                error = true;
                                Report.error (param.source_reference, "Reference parameters are not supported 
for async methods");
                        }
+                       if (optional_param && param.initializer == null) {
+                               Report.warning (param.source_reference, "parameter without default follows 
parameter with default");
+                       } else if (param.initializer != null) {
+                               optional_param = true;
+                       }
                }
 
                foreach (DataType error_type in get_error_types ()) {
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 9f6d77c..934d026 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -3449,7 +3449,7 @@ namespace GLib {
                public string[] split_full (string str, ssize_t string_len = -1, int start_position = 0, 
RegexMatchFlags match_options = 0, int max_tokens = 0) throws RegexError;
                public string replace (string str, ssize_t string_len, int start_position, string 
replacement, RegexMatchFlags match_options = 0) throws RegexError;
                public string replace_literal (string str, ssize_t string_len, int start_position, string 
replacement, RegexMatchFlags match_options = 0) throws RegexError;
-               public string replace_eval (string str, ssize_t string_len, int start_position, 
RegexMatchFlags match_options = 0, RegexEvalCallback eval) throws RegexError;
+               public string replace_eval (string str, ssize_t string_len, int start_position, 
RegexMatchFlags match_options, RegexEvalCallback eval) throws RegexError;
                public static bool check_replacement (out bool has_references = null) throws RegexError;
        }
 


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