From: Juerg Billeter Date: Wed, 12 Dec 2007 17:27:33 +0000 (+0000) Subject: verify that the `abstract', `virtual', and `overrides' method modifiers X-Git-Tag: VALA_0_1_6~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1ffc928b95243dd03be48895b4bb83a329c9dff;p=thirdparty%2Fvala.git verify that the `abstract', `virtual', and `overrides' method modifiers 2007-12-12 Juerg Billeter * vala/valasemanticanalyzer.vala: verify that the `abstract', `virtual', and `overrides' method modifiers are used only where applicable svn path=/trunk/; revision=764 --- diff --git a/ChangeLog b/ChangeLog index bfb4487ac..d98d44087 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-12 Jürg Billeter + + * vala/valasemanticanalyzer.vala: verify that the `abstract', `virtual', + and `overrides' method modifiers are used only where applicable + 2007-12-12 Jürg Billeter * gobject/valaccodegeneratormethod.vala: fix invalid C code for virtual diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index ee65ecd25..75c1f48c8 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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;