]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Warn when hiding members, support `new' keyword to suppress warning, based
authorJürg Billeter <j@bitron.ch>
Thu, 12 Feb 2009 23:38:42 +0000 (23:38 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 12 Feb 2009 23:38:42 +0000 (23:38 +0000)
2009-02-12  Jürg Billeter  <j@bitron.ch>

* vala/valaclass.vala:
* vala/valaconstant.vala:
* vala/valafield.vala:
* vala/valamember.vala:
* vala/valamethod.vala:
* vala/valaproperty.vala:
* vala/valastruct.vala:

Warn when hiding members, support `new' keyword to suppress
warning, based on patch by Andreas Brauchli, fixes bug 567743

* vala/valacodenode.vala:
* vala/valacreationmethod.vala:
* vala/valaenum.vala:
* vala/valaerrordomain.vala:
* vala/valanamespace.vala:
* ccode/valaccodelinedirective.vala:

Avoid hidden members

svn path=/trunk/; revision=2437

14 files changed:
ChangeLog
ccode/valaccodelinedirective.vala
vala/valaclass.vala
vala/valacodenode.vala
vala/valaconstant.vala
vala/valacreationmethod.vala
vala/valaenum.vala
vala/valaerrordomain.vala
vala/valafield.vala
vala/valamember.vala
vala/valamethod.vala
vala/valanamespace.vala
vala/valaproperty.vala
vala/valastruct.vala

index 854bbaa830ee0397af22cd4e4de2ea9fed8efb7f..2156b25db978342ecb35b5fbfeb559ab2cd8deef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2009-02-12  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaclass.vala:
+       * vala/valaconstant.vala:
+       * vala/valafield.vala:
+       * vala/valamember.vala:
+       * vala/valamethod.vala:
+       * vala/valaproperty.vala:
+       * vala/valastruct.vala:
+
+       Warn when hiding members, support `new' keyword to suppress
+       warning, based on patch by Andreas Brauchli, fixes bug 567743
+
+       * vala/valacodenode.vala:
+       * vala/valacreationmethod.vala:
+       * vala/valaenum.vala:
+       * vala/valaerrordomain.vala:
+       * vala/valanamespace.vala:
+       * ccode/valaccodelinedirective.vala:
+
+       Avoid hidden members
+
 2009-02-12  Jürg Billeter  <j@bitron.ch>
 
        * vala/valastruct.vala:
index 8f674788921f50a7ed08e1386cf903174a28dfac..96b0e017b9e8fa1c8d1b229ec82d78cf167a42eb 100644 (file)
@@ -34,18 +34,18 @@ public class Vala.CCodeLineDirective : CCodeNode {
        /**
         * The line number in the source file to be presumed.
         */
-       public int line { get; set; }
+       public int line_number { get; set; }
        
        public CCodeLineDirective (string _filename, int _line) {
                filename = _filename;
-               line = _line;
+               line_number = _line;
        }
 
        public override void write (CCodeWriter writer) {
                if (!writer.bol) {
                        writer.write_newline ();
                }
-               writer.write_string ("#line %d \"%s\"".printf (line, filename));
+               writer.write_string ("#line %d \"%s\"".printf (line_number, filename));
                writer.write_newline ();
        }
 }
index 1627eaa4c4f3406729480ad3083506a285e04013..6cece1ffd80312194ae168b5bde969b24635ad06 100644 (file)
@@ -329,9 +329,9 @@ public class Vala.Class : ObjectTypeSymbol {
                        }
 
                        var cm = (CreationMethod) m;
-                       if (cm.type_name != null && cm.type_name != name) {
-                               // type_name is null for constructors generated by GIdlParser
-                               Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.type_name));
+                       if (cm.class_name != null && cm.class_name != name) {
+                               // class_name is null for constructors generated by GIdlParser
+                               Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.class_name));
                                m.error = true;
                                return;
                        }
index 015f227dab83c5a017204158bd0869d509a4652d..bcee17efeb3f9ff6977fc4f8c185fa3d45c39277 100644 (file)
@@ -45,6 +45,10 @@ public abstract class Vala.CodeNode {
         * Contains all attributes that have been specified for this code node.
         */
        public GLib.List<Attribute> attributes;
+
+       public string type_name {
+               get { return Type.from_instance (this).name (); }
+       }
        
        /**
         * Generated CCodeNode that corresponds to this code node.
@@ -189,8 +193,4 @@ public abstract class Vala.CodeNode {
        public string get_temp_name () {
                return "." + (++last_temp_nr).to_string ();
        }
-
-       public weak string get_type_name () {
-               return Type.from_instance (this).name ();
-       }
 }
index d8fc272dfa229ee75737fffc700c9d96e43ffd45..dd5c4a8dc2b5e0f0857ed606ad0b68a9e4319967 100644 (file)
@@ -181,6 +181,10 @@ public class Vala.Constant : Member, Lockable {
                        }
                }
 
+               if (!external_package && !hides && get_hidden_member () != null) {
+                       Report.warning (source_reference, "%s hides inherited constant `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
+               }
+
                analyzer.current_source_file = old_source_file;
                analyzer.current_symbol = old_symbol;
 
index fbdf9aa90c73fed08cac5590fb2a33ba2f2d458c..8700b05648d9f7363cbe8f3004e58bb83999d23f 100644 (file)
@@ -31,7 +31,7 @@ public class Vala.CreationMethod : Method {
        /**
         * Specifies the name of the type this creation method belongs to.
         */
-       public string type_name { get; set; }
+       public string class_name { get; set; }
 
        /**
         * Specifies the number of parameters this creation method sets.
@@ -59,9 +59,9 @@ public class Vala.CreationMethod : Method {
         * @param source_reference reference to source code
         * @return                 newly created method
         */
-       public CreationMethod (string? type_name, string? name, SourceReference? source_reference = null) {
+       public CreationMethod (string? class_name, string? name, SourceReference? source_reference = null) {
                base (name, new VoidType (), source_reference);
-               this.type_name = type_name;
+               this.class_name = class_name;
 
                carray_length_parameter_position = -3;
                cdelegate_target_parameter_position = -3;
@@ -125,9 +125,9 @@ public class Vala.CreationMethod : Method {
 
                process_attributes ();
 
-               if (type_name != null && type_name != parent_symbol.name) {
-                       // type_name is null for constructors generated by GIdlParser
-                       Report.error (source_reference, "missing return type in method `%s.%s´".printf (analyzer.current_symbol.get_full_name (), type_name));
+               if (class_name != null && class_name != parent_symbol.name) {
+                       // class_name is null for constructors generated by GIdlParser
+                       Report.error (source_reference, "missing return type in method `%s.%s´".printf (analyzer.current_symbol.get_full_name (), class_name));
                        error = true;
                        return false;
                }
index e709f866034118f025ac199a216aba8c51e7a445..1d1e8c1120f84969a8153446b243f7da821690b2 100644 (file)
@@ -165,13 +165,7 @@ public class Vala.Enum : TypeSymbol {
                return false;
        }
 
-       /**
-        * Returns the string to be prepended to the name of members of this
-        * enum when used in C code.
-        *
-        * @return the prefix to be used in C code
-        */
-       public string get_cprefix () {
+       public override string get_cprefix () {
                if (cprefix == null) {
                        cprefix = "%s_".printf (get_upper_case_cname ());
                }
index 713e452ed69f0897150e48b92b310c91eb5b7a86..eecd97c8ecbdd16bbacf3165887fde97ea4f2ed7 100644 (file)
@@ -148,13 +148,7 @@ public class Vala.ErrorDomain : TypeSymbol {
                this.cname = cname;
        }
        
-       /**
-        * Returns the string to be prepended to the name of members of this
-        * error domain when used in C code.
-        *
-        * @return the prefix to be used in C code
-        */
-       public string get_cprefix () {
+       public override string get_cprefix () {
                if (cprefix == null) {
                        cprefix = "%s_".printf (get_upper_case_cname (null));
                }
index d24491e8bb2f41fd31120af8b9a046099fbfa048..24ac796e73be7abf2dae52af3c81e62aeb951fa8 100644 (file)
@@ -321,6 +321,10 @@ public class Vala.Field : Member, Lockable {
                        }
                }
 
+               if (!external_package && !hides && get_hidden_member () != null) {
+                       Report.warning (source_reference, "%s hides inherited field `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
+               }
+
                if (field_in_header) {
                        if (field_type is ValueType) {
                                analyzer.current_source_file.add_type_dependency (field_type, SourceFileDependencyType.HEADER_FULL);
index 7da055f58384de5b3751a7b18776e3e60aa74513..8628d1a691e3c7bc99e83739a561801caf63d731 100644 (file)
@@ -68,6 +68,32 @@ public abstract class Vala.Member : Symbol {
        public void add_cheader_filename (string filename) {
                cheader_filenames.add (filename);
        }
+
+       public Symbol? get_hidden_member () {
+               Symbol sym = null;
+
+               if (parent_symbol is Class) {
+                       var cl = ((Class) parent_symbol).base_class;
+                       while (cl != null) {
+                               sym = cl.scope.lookup (name);
+                               if (sym != null && sym.access != SymbolAccessibility.PRIVATE) {
+                                       return sym;
+                               }
+                               cl = cl.base_class;
+                       }
+               } else if (parent_symbol is Struct) {
+                       var st = ((Struct) parent_symbol).base_struct;
+                       while (st != null) {
+                               sym = st.scope.lookup (name);
+                               if (sym != null && sym.access != SymbolAccessibility.PRIVATE) {
+                                       return sym;
+                               }
+                               st = st.base_struct;
+                       }
+               }
+
+               return null;
+       }
 }
 
 public enum MemberBinding {
index 231a945a971dda0b10ea0359e486adb571b1a08e..ae3207edd084f24a5c663a2aebc8cbd271627017 100644 (file)
@@ -744,6 +744,10 @@ public class Vala.Method : Member {
                        Report.error (source_reference, "%s: no suitable method found to override".printf (get_full_name ()));
                }
 
+               if (!external_package && !overrides && !hides && get_hidden_member () != null) {
+                       Report.warning (source_reference, "%s hides inherited method `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
+               }
+
                // check whether return type is at least as accessible as the method
                if (!analyzer.is_type_accessible (this, return_type)) {
                        error = true;
index a113381a57f2cccf92fb256af439261284800408..1c0d9ad457742522a7be5fff363c58926182dd51 100644 (file)
@@ -86,7 +86,7 @@ public class Vala.Namespace : Symbol {
                        foreach (Enum en in ns.get_enums ()) {
                                old_ns.add_enum (en);
                        }
-                       foreach (ErrorDomain ed in ns.get_error_types ()) {
+                       foreach (ErrorDomain ed in ns.get_error_domains ()) {
                                old_ns.add_error_domain (ed);
                        }
                        foreach (Constant c in ns.get_constants ()) {
@@ -254,7 +254,7 @@ public class Vala.Namespace : Symbol {
         *
         * @return error domain list
         */
-       public Gee.List<ErrorDomain> get_error_types () {
+       public Gee.List<ErrorDomain> get_error_domains () {
                return new ReadOnlyList<ErrorDomain> (error_domains);
        }
        
index 52e65733d6dec1725401ca6e0582474e84d35346..b138c547dc626934d780a7956c323ac9c5ef503f 100644 (file)
@@ -448,6 +448,10 @@ public class Vala.Property : Member, Lockable {
                        Report.error (source_reference, "%s: no suitable property found to override".printf (get_full_name ()));
                }
 
+               if (!external_package && !overrides && !hides && get_hidden_member () != null) {
+                       Report.warning (source_reference, "%s hides inherited property `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
+               }
+
                /* construct properties must be public */
                if (set_accessor != null && set_accessor.construction) {
                        if (access != SymbolAccessibility.PUBLIC) {
index d517aba658d7f05becf469f4f07ba953f0776fe2..6962b2938678bbd7d2a90e003feb6756b1d1b640 100644 (file)
@@ -177,9 +177,9 @@ public class Vala.Struct : TypeSymbol {
                        }
 
                        var cm = (CreationMethod) m;
-                       if (cm.type_name != null && cm.type_name != name) {
+                       if (cm.class_name != null && cm.class_name != name) {
                                // type_name is null for constructors generated by GIdlParser
-                               Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.type_name));
+                               Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.class_name));
                                m.error = true;
                                return;
                        }