diff options
author | Yotam Nachum <me@yotam.net> | 2021-11-06 19:05:13 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-11-12 15:32:08 +0100 |
commit | af730d4eef2879b487fff6f949a01b69b3b78f5f (patch) | |
tree | 4f8bc0df14b3cb905e6213064635233857b082cc /vala/valacastexpression.vala | |
parent | 88801eb4266a8c2d33176739c7f24b6b6cedd774 (diff) | |
download | vala-af730d4eef2879b487fff6f949a01b69b3b78f5f.tar.gz |
vala: Don't allow casting real structs to classes or simple-types
This led to C compiler errors or obvious runtimes failures.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1249
Diffstat (limited to 'vala/valacastexpression.vala')
-rw-r--r-- | vala/valacastexpression.vala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala index 732b99a71..5d0783e41 100644 --- a/vala/valacastexpression.vala +++ b/vala/valacastexpression.vala @@ -170,6 +170,15 @@ public class Vala.CastExpression : Expression { return false; } + // Allow casting to array or pointer type + if (!(type_reference is ArrayType || type_reference is PointerType)) { + if (!type_reference.is_real_struct_type () && inner.value_type.is_real_struct_type () + && (context.profile != Profile.GOBJECT || !(is_gvariant (context, inner.value_type) || is_gvalue (context, inner.value_type)))) { + error = true; + Report.error (source_reference, "Casting of struct `%s' to `%s' is not allowed", inner.value_type.to_qualified_string (), type_reference.to_qualified_string ()); + } + } + if (type_reference is DelegateType && inner.value_type is MethodType) { if (target_type != null) { inner.value_type.value_owned = target_type.value_owned; |