From: Jürg Billeter Date: Sat, 15 Aug 2009 14:11:11 +0000 (+0200) Subject: Report error on missing or duplicate entry point X-Git-Tag: 0.7.6~209 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc6154a777481a441bdf0e444a47107045a4fb81;p=thirdparty%2Fvala.git Report error on missing or duplicate entry point Fixes bug 591819. --- diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 06c8bf6d3..cc74b5cc0 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -313,6 +313,13 @@ class Vala.Compiler { var analyzer = new SemanticAnalyzer (); analyzer.analyze (context); + if (!ccode_only && !compile_only) { + // building program, require entry point + if (context.entry_point == null) { + Report.error (null, "program does not contain a static `main' method"); + } + } + if (dump_tree != null) { var code_writer = new CodeWriter (true); code_writer.write_file (context, dump_tree); diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 62a6ac670..a6d783c48 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -145,6 +145,8 @@ public class Vala.CodeContext { public Report report { get; set; default = new Report ();} + public Method? entry_point { get; set; } + private Gee.List source_files = new ArrayList (); private Gee.List c_source_files = new ArrayList (); private Namespace _root = new Namespace (null); diff --git a/vala/valamethod.vala b/vala/valamethod.vala index b575c8fcb..7b2804242 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -850,7 +850,13 @@ public class Vala.Method : Member { } if (is_possible_entry_point (analyzer)) { + if (analyzer.context.entry_point != null) { + error = true; + Report.error (source_reference, "program already has an entry point `%s'".printf (analyzer.context.entry_point.get_full_name ())); + return false; + } entry_point = true; + analyzer.context.entry_point = this; } return !error;