]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report error on unsupported type check expressions
authorJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 14:56:39 +0000 (16:56 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 16 Aug 2009 14:56:39 +0000 (16:56 +0200)
Fixes bug 585344.

ccode/Makefile.am
ccode/valaccodeinvalidexpression.vala [new file with mode: 0644]
codegen/valaccodebasemodule.vala

index d70c568973d29d66756e33ab0a5460b172d6c0c7..af79c1f96f830508ac2c0e15ab9f3a5c0d146948 100644 (file)
@@ -42,6 +42,7 @@ libvalaccode_la_VALASOURCES = \
        valaccodeifstatement.vala \
        valaccodeincludedirective.vala \
        valaccodeinitializerlist.vala \
+       valaccodeinvalidexpression.vala \
        valaccodelabel.vala \
        valaccodelinedirective.vala \
        valaccodemacroreplacement.vala \
diff --git a/ccode/valaccodeinvalidexpression.vala b/ccode/valaccodeinvalidexpression.vala
new file mode 100644 (file)
index 0000000..cf01e31
--- /dev/null
@@ -0,0 +1,33 @@
+/* valaccodeinvalidexpression.vala
+ *
+ * Copyright (C) 2009  Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+/**
+ * Represents an invalid expression.
+ */
+public class Vala.CCodeInvalidExpression : CCodeExpression {
+       public CCodeInvalidExpression () {
+       }
+
+       public override void write (CCodeWriter writer) {
+               assert_not_reached ();
+       }
+}
index 0cfdb307b3734d1df8ce370fea1277c2281c4071..a970c3a5a557ef341996614daa6ba7666e569878 100644 (file)
@@ -3656,16 +3656,18 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                expr.ccodenode = new CCodeBinaryExpression (op, cleft, cright);
        }
 
-       public string get_type_check_function (TypeSymbol type) {
+       public string? get_type_check_function (TypeSymbol type) {
                var cl = type as Class;
                if (cl != null && cl.type_check_function != null) {
                        return cl.type_check_function;
+               } else if ((cl != null && cl.is_compact) || type is Struct || type is Enum || type is Delegate) {
+                       return null;
                } else {
                        return type.get_upper_case_cname ("IS_");
                }
        }
 
-       CCodeExpression create_type_check (CCodeNode ccodenode, DataType type) {
+       CCodeExpression? create_type_check (CCodeNode ccodenode, DataType type) {
                var et = type as ErrorType;
                if (et != null && et.error_code != null) {
                        var matches_call = new CCodeFunctionCall (new CCodeIdentifier ("g_error_matches"));
@@ -3678,7 +3680,11 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                        var type_domain = new CCodeIdentifier (et.error_domain.get_upper_case_cname ());
                        return new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, instance_domain, type_domain);
                } else {
-                       var ccheck = new CCodeFunctionCall (new CCodeIdentifier (get_type_check_function (type.data_type)));
+                       string type_check_func = get_type_check_function (type.data_type);
+                       if (type_check_func == null) {
+                               return new CCodeInvalidExpression ();
+                       }
+                       var ccheck = new CCodeFunctionCall (new CCodeIdentifier (type_check_func));
                        ccheck.add_argument ((CCodeExpression) ccodenode);
                        return ccheck;
                }
@@ -3688,6 +3694,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                generate_type_declaration (expr.type_reference, source_declarations);
 
                expr.ccodenode = create_type_check (expr.expression.ccodenode, expr.type_reference);
+               if (expr.ccodenode is CCodeInvalidExpression) {
+                       Report.error (expr.source_reference, "type check expressions not supported for compact classes, structs, and enums");
+               }
        }
 
        public override void visit_lambda_expression (LambdaExpression l) {