]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not allow passing owned ref argument to unowned reference parameter
authorJürg Billeter <j@bitron.ch>
Thu, 14 Oct 2010 12:32:07 +0000 (14:32 +0200)
committerJürg Billeter <j@bitron.ch>
Thu, 14 Oct 2010 12:35:08 +0000 (14:35 +0200)
compiler/valacompiler.vala
tests/objects/methods.vala
vala/valasemanticanalyzer.vala

index 46a1cf0f2f7844acf2ec3ada5f1e4992ccc8eff8..37da5242d7cee1b85afe1d0ea54986c09374a184 100644 (file)
@@ -485,7 +485,8 @@ class Vala.Compiler {
                                var opt_context = new OptionContext ("- Vala");
                                opt_context.set_help_enabled (true);
                                opt_context.add_main_entries (options, null);
-                               opt_context.parse (ref compile_args);
+                               unowned string[] temp_args = compile_args;
+                               opt_context.parse (ref temp_args);
                        } catch (ShellError e) {
                                stdout.printf ("%s\n", e.message);
                                return 1;
index 49834bdd44b3c5a1a0fbfb995e880a009cee9948..027a53da15b5f15189addf72db23d8a95a00d0dd 100644 (file)
@@ -78,9 +78,6 @@ class Maman.SubBar : Bar {
                test_ref_weak (ref weak_str);
                assert (str == "world");
 
-               test_ref_weak (ref str2);
-               assert (str == "world");
-
                ClassTest.run_test ();
 
                return 0;
index 111c614e713be805086f7a2a77c112bc4ac9ee94..c6b718b90c2f09eda2094c5a7a80c9cc4fd54269 100644 (file)
@@ -549,7 +549,16 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                if (arg.target_type.is_disposable ()) {
                                        if (!(arg.value_type is PointerType) && !arg.value_type.value_owned) {
                                                /* variable doesn't own the value */
-                                               Report.error (arg.source_reference, "Invalid assignment from owned expression to unowned variable");
+                                               Report.error (arg.source_reference, "Argument %d: Cannot pass unowned ref argument to owned reference parameter".printf (i + 1));
+                                               return false;
+                                       }
+                               }
+
+                               // owned variables can only be used with owned ref parameters
+                               if (arg.value_type.is_disposable ()) {
+                                       if (!arg.target_type.value_owned) {
+                                               /* parameter doesn't own the value */
+                                               Report.error (arg.source_reference, "Argument %d: Cannot pass owned ref argument to unowned reference parameter".printf (i + 1));
                                                return false;
                                        }
                                }