From dc830f848032e0c1368e4fc16e1cf7538dc5dbf3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sun, 1 Jun 2008 11:31:44 +0000 Subject: [PATCH] Report error when trying to use unowned variables as argument for owned MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- ChangeLog | 7 +++++++ vala/valasemanticanalyzer.vala | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) 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; + } + } } } -- 2.7.4