From: Jürg Billeter Date: Sun, 1 Jun 2008 11:31:44 +0000 (+0000) Subject: Report error when trying to use unowned variables as argument for owned X-Git-Tag: VALA_0_3_3~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc830f848032e0c1368e4fc16e1cf7538dc5dbf3;p=platform%2Fupstream%2Fvala.git Report error when trying to use unowned variables as argument for owned 2008-06-01 Jürg Billeter * vala/valasemanticanalyzer.vala: Report error when trying to use unowned variables as argument for owned reference and output parameters svn path=/trunk/; revision=1526 --- diff --git a/ChangeLog b/ChangeLog index eff7433..d01abb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,13 @@ * vala/valasemanticanalyzer.vala: + Report error when trying to use unowned variables as argument + for owned reference and output parameters + +2008-06-01 Jürg Billeter + + * vala/valasemanticanalyzer.vala: + Report internal error for missing type argument 2008-05-31 Jürg Billeter diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index f54d2bd..d2a38ea 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -2042,12 +2042,32 @@ public class Vala.SemanticAnalyzer : CodeVisitor { Report.error (arg.source_reference, "Argument %d: Cannot pass ref argument to non-reference parameter".printf (i + 1)); return false; } + + // weak variables can only be used with weak ref parameters + if (param.parameter_type.is_disposable ()) { + if (!(arg.value_type is PointerType) && !arg.value_type.value_owned) { + /* variable doesn't own the value */ + expr.error = true; + Report.error (arg.source_reference, "Invalid assignment from owned expression to unowned variable"); + return false; + } + } } else if (arg_type == 3) { if (param.direction != ParameterDirection.OUT) { expr.error = true; Report.error (arg.source_reference, "Argument %d: Cannot pass out argument to non-output parameter".printf (i + 1)); return false; } + + // weak variables can only be used with weak out parameters + if (param.parameter_type.is_disposable ()) { + if (!(arg.value_type is PointerType) && !arg.value_type.value_owned) { + /* variable doesn't own the value */ + expr.error = true; + Report.error (arg.source_reference, "Invalid assignment from owned expression to unowned variable"); + return false; + } + } } }