]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
verify that the `abstract', `virtual', and `overrides' method modifiers
authorJuerg Billeter <j@bitron.ch>
Wed, 12 Dec 2007 17:27:33 +0000 (17:27 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 12 Dec 2007 17:27:33 +0000 (17:27 +0000)
2007-12-12  Juerg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala: verify that the `abstract', `virtual',
  and `overrides' method modifiers are used only where applicable

svn path=/trunk/; revision=764

ChangeLog
vala/valasemanticanalyzer.vala

index bfb4487acf9c15adcdaf120c31aaae5cf84d78e0..d98d44087cc5a06ab091b1f7c97613693e829472 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-12  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valasemanticanalyzer.vala: verify that the `abstract', `virtual',
+         and `overrides' method modifiers are used only where applicable
+
 2007-12-12  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodegeneratormethod.vala: fix invalid C code for virtual
index ee65ecd254bb8c90e5fdf9b7f6ac2db4e6058171..75c1f48c89ddcd1b0d8f175e2758cfb8ccee068f 100644 (file)
@@ -341,6 +341,33 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
 
        public override void visit_method (Method! m) {
+               if (m.is_abstract) {
+                       if (m.parent_symbol is Class) {
+                               var cl = (Class) m.parent_symbol;
+                               if (!cl.is_abstract) {
+                                       m.error = true;
+                                       Report.error (m.source_reference, "Abstract methods may not be declared in non-abstract classes");
+                                       return;
+                               }
+                       } else if (!(m.parent_symbol is Interface)) {
+                               m.error = true;
+                               Report.error (m.source_reference, "Abstract methods may not be declared outside of classes and interfaces");
+                               return;
+                       }
+               } else if (m.is_virtual) {
+                       if (!(m.parent_symbol is Class)) {
+                               m.error = true;
+                               Report.error (m.source_reference, "Virtual methods may not be declared outside of classes");
+                               return;
+                       }
+               } else if (m.overrides) {
+                       if (!(m.parent_symbol is Class)) {
+                               m.error = true;
+                               Report.error (m.source_reference, "Methods may not be overridden outside of classes");
+                               return;
+                       }
+               }
+
                current_symbol = m;
                current_return_type = m.return_type;