]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Warn about mismatched parameter direction before mismatched type
authorSam Thursfield <ssssam@gmail.com>
Wed, 30 Nov 2011 16:26:00 +0000 (17:26 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 13 Oct 2016 08:55:20 +0000 (10:55 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=664049

vala/valasemanticanalyzer.vala

index ef023e10192483d5c57e3ff36fea524e5682a220..f3b1a633d85dcc39c75460d694fe41aba13ed810 100644 (file)
@@ -483,17 +483,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                Report.error (arg.source_reference, "Invalid type for argument %d".printf (i + 1));
                                return false;
                        }
-               } else if (arg.target_type != null
-                          && (direction == ParameterDirection.IN || direction == ParameterDirection.REF)
-                          && !arg.value_type.compatible (arg.target_type)) {
-                       Report.error (arg.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.value_type.to_string (), arg.target_type.to_string ()));
-                       return false;
-               } else if (arg.target_type != null
-                          && (direction == ParameterDirection.REF || direction == ParameterDirection.OUT)
-                          && !arg.target_type.compatible (arg.value_type)
-                          && !(arg is NullLiteral)) {
-                       Report.error (arg.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.target_type.to_string (), arg.value_type.to_string ()));
-                       return false;
                } else {
                        // 0 => null, 1 => in, 2 => ref, 3 => out
                        int arg_type = 1;
@@ -559,6 +548,20 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                }
                        }
                }
+
+               if (arg.target_type != null) {
+                       if ((direction == ParameterDirection.IN || direction == ParameterDirection.REF)
+                           && !arg.value_type.compatible (arg.target_type)) {
+                               Report.error (arg.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.value_type.to_string (), arg.target_type.to_string ()));
+                               return false;
+                       } else if ((direction == ParameterDirection.REF || direction == ParameterDirection.OUT)
+                               && !arg.target_type.compatible (arg.value_type)
+                               && !(arg is NullLiteral)) {
+                               Report.error (arg.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.target_type.to_string (), arg.value_type.to_string ()));
+                               return false;
+                       }
+               }
+
                var ma = arg as MemberAccess;
                if (ma != null && ma.prototype_access) {
                        // allow prototype access if target type is delegate without target