From: Vadim Z. <vz...@ze...> - 2010-06-02 16:05:39
|
Hello, Consider this (contrived) example: % cat -n enum_with_same_name.i 1 %module enum_with_same_name; 2 3 %inline %{ 4 enum Month { Jan, May, Dec }; 5 enum Severity { May, Can, Must }; 6 %} SWIG complains about this: % swig -c++ -csharp enum_with_same_name.i enum_with_same_name.i:5: Warning 302: Identifier 'May' redefined (ignored), enum_with_same_name.i:4: Warning 302: previous definition of 'May'. and generates invalid C# code because of the missing element: % gmcs Severity.cs Severity.cs(11,1): error CS8025: Parsing error Compilation failed: 1 error(s), 0 warnings % cat -n Severity.cs 1 /* ---------------------------------------------------------------------------- 2 * This file was automatically generated by SWIG (http://www.swig.org). 3 * Version 2.0.0 4 * 5 * Do not make changes to this file unless you know what you are doing--modify 6 * the SWIG interface file instead. 7 * ----------------------------------------------------------------------------- */ 8 9 10 public enum Severity { 11 , 12 Can, 13 Must 14 } With Java the situation is the same except that the generated code is valid and compiles without errors which is arguably even worse as you may not notice at all that some of the enum elements are not wrapped. AFAIK there are no restrictions on using the same names in different enums in neither Java nor C# so this looks like a SWIG bug to me. Unfortunately I don't know how to fix it, from looking at Source/CParse/parser.y it seems that all enum elements are added using their names to the internal symbol table and this can't work in this case... Any ideas about how to work around this issue except for %renaming the enum elements to have a unique prefix (which is what I do now and it does work but this results in unwanted redundancy in C#/Java code)? TIA, VZ |