]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Make sure type check expression has valid type
authorSimon Werbeck <simon.werbeck@gmail.com>
Wed, 13 Aug 2014 00:51:11 +0000 (02:51 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 24 Aug 2014 11:55:57 +0000 (13:55 +0200)
Fixes bug 696729

codegen/valaccodebasemodule.vala

index dae33347f260687a604141060ebc81c7fda70c12..ca282a1619eaaadd9751447bb1961514c05b0eaf 100644 (file)
@@ -5456,7 +5456,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public override void visit_type_check (TypeCheck expr) {
                generate_type_declaration (expr.type_reference, cfile);
 
-               set_cvalue (expr, create_type_check (get_cvalue (expr.expression), expr.type_reference));
+               var type = expr.expression.value_type;
+               var pointer_type = type as PointerType;
+               if (pointer_type != null) {
+                       type = pointer_type.base_type;
+               }
+               var cl = type.data_type as Class;
+               var iface = type.data_type as Interface;
+               if ((cl != null && !cl.is_compact) || iface != null || type is GenericType || type is ErrorType) {
+                       set_cvalue (expr, create_type_check (get_cvalue (expr.expression), expr.type_reference));
+               } else {
+                       set_cvalue (expr, new CCodeInvalidExpression ());
+               }
+
                if (get_cvalue (expr) is CCodeInvalidExpression) {
                        Report.error (expr.source_reference, "type check expressions not supported for compact classes, structs, and enums");
                }