From b1ffc928b95243dd03be48895b4bb83a329c9dff Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Wed, 12 Dec 2007 17:27:33 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ vala/valasemanticanalyzer.vala | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index bfb4487..d98d440 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 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 interface method implementations diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index ee65ecd..75c1f48 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; -- 2.7.4