[vala/staging] vala: Warn when directly accessing member of silent cast-expression
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Warn when directly accessing member of silent cast-expression
- Date: Wed, 25 Sep 2019 12:34:29 +0000 (UTC)
commit 3049558912c04eea9eefef5b05b5342f0f9f4f10
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Sep 23 15:56:49 2019 +0200
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".
vala/valamemberaccess.vala | 4 ++++
1 file changed, 4 insertions(+)
---
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]