]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GObject: Check arguments of Object constructor chain up
authorJürg Billeter <j@bitron.ch>
Wed, 21 Oct 2009 21:17:54 +0000 (23:17 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 21 Oct 2009 21:17:54 +0000 (23:17 +0200)
codegen/valagobjectmodule.vala

index cc1e7bfb80a191925ef692435db91d61a7ee17c5..462c38a0676524e4f1add18fb3b6ec08b551cc9b 100644 (file)
@@ -711,5 +711,30 @@ internal class Vala.GObjectModule : GTypeModule {
 
                return true;
        }
+
+       public override void visit_method_call (MethodCall expr) {
+               if (expr.call is MemberAccess && expr.call.symbol_reference == gobject_type) {
+                       // Object (...) chain up
+                       // check it's only used with valid properties
+                       foreach (var arg in expr.get_argument_list ()) {
+                               var named_argument = arg as NamedArgument;
+                               if (named_argument == null) {
+                                       Report.error (arg.source_reference, "Named argument expected");
+                                       break;
+                               }
+                               var prop = SemanticAnalyzer.symbol_lookup_inherited (current_class, named_argument.name) as Property;
+                               if (prop == null) {
+                                       Report.error (arg.source_reference, "Property `%s' not found in `%s'".printf (named_argument.name, current_class.get_full_name ()));
+                                       break;
+                               }
+                               if (!arg.value_type.compatible (prop.property_type)) {
+                                       Report.error (arg.source_reference, "Cannot convert from `%s' to `%s'".printf (arg.value_type.to_string (), prop.property_type.to_string ()));
+                                       break;
+                               }
+                       }
+               }
+
+               base.visit_method_call (expr);
+       }
 }