From: Rico Tzschichholz Date: Mon, 23 Sep 2019 13:56:49 +0000 (+0200) Subject: vala: Warn when directly accessing member of silent cast-expression X-Git-Tag: 0.47.1~149 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fkeep-around%2F72061ee0286a4ce37ddec976174cc3786b3e4a59;p=thirdparty%2Fvala.git vala: Warn when directly accessing member of silent cast-expression "foo as TypeSymbol" may result in `null' and accessing it without check is not recommended. If the invocation context provides information that `null' is not a possible result then use an unsafe cast "(TypeSymbol) foo". --- diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index 37eeafb87..ad3f3d0fc 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -343,6 +343,10 @@ public class Vala.MemberAccess : Expression { } } + if (inner is CastExpression && ((CastExpression) inner).is_silent_cast) { + Report.warning (source_reference, "Access to possible `null'. Perform a check or use an unsafe cast."); + } + if (inner is MemberAccess || inner is BaseAccess) { base_symbol = inner.symbol_reference;