[vala] Do not allow passing owned ref argument to unowned reference parameter
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Do not allow passing owned ref argument to unowned reference parameter
- Date: Thu, 14 Oct 2010 12:59:40 +0000 (UTC)
commit d5eb505c1b5bfe61f5174a7422c98e33c4c5909e
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 14 14:32:07 2010 +0200
Do not allow passing owned ref argument to unowned reference parameter
compiler/valacompiler.vala | 3 ++-
tests/objects/methods.vala | 3 ---
vala/valasemanticanalyzer.vala | 11 ++++++++++-
3 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 46a1cf0..37da524 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -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;
diff --git a/tests/objects/methods.vala b/tests/objects/methods.vala
index 49834bd..027a53d 100644
--- a/tests/objects/methods.vala
+++ b/tests/objects/methods.vala
@@ -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;
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 111c614..c6b718b 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]