]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix type checking for ref and out arguments
authorJürg Billeter <j@bitron.ch>
Sat, 6 Jun 2009 18:15:34 +0000 (20:15 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 6 Jun 2009 18:18:56 +0000 (20:18 +0200)
Fixes bug 570058.

vala/valasemanticanalyzer.vala

index cf3c1e66f399b7894146838841afd4669d6c6fa5..755b0ae5808afb25cb45e4d4a7bc9cdf12c2ec89 100644 (file)
@@ -386,10 +386,17 @@ 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 && !arg.value_type.compatible (arg.target_type)
-                          && !(arg is NullLiteral && direction == ParameterDirection.OUT)) {
+               } 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;