]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Warn when directly accessing member of silent cast-expression 72061ee0286a4ce37ddec976174cc3786b3e4a59
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 23 Sep 2019 13:56:49 +0000 (15:56 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 25 Sep 2019 13:19:25 +0000 (15:19 +0200)
"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".

vala/valamemberaccess.vala

index 37eeafb875f27e53245009050a664df5cd2f91f8..ad3f3d0fc9e3d6a8a342feae409ba77887620dbf 100644 (file)
@@ -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;