[Ikvm-developers] Using Java annotation class fails with Mono.
Brought to you by:
jfrijters
From: Dawid W. <daw...@cs...> - 2010-07-22 14:38:02
|
Hi there, I have a bug (?) I couldn't understand the source of, perhaps you'll share my interest in finding out what's happening. We ikvm-compile a Java annotation class that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Bindable { String prefix() default ""; } then we place this annotation in C# code on a C# class: namespace Org.Carrot2.Core { [org.carrot2.util.attribute.Bindable(prefix = "component")] public class ComponentWithAttributes : org.carrot2.core.ProcessingComponentBase [...] This works like a charm with Microsoft .NET compiler, but fails with mono (tried various revisions, the latest one Mono C# compiler version 2.6.7.0): TypeAdaptersTest.cs(10,33): error CS0122: `org.carrot2.util.attribute.BindableAttribute.prefix()' is inaccessible due to its protection level C:\PROGRA~2\MONO-2~1.7\lib\mono\2.0\gmcs.exe (Location of the symbol related to previous error) Compilation failed: 1 error(s), 0 warnings When looking at the decompilation of BindableAttribute (which is the annotation's implementation class generated by ikvm) one sees this: .method private newslot virtual final instance string prefix() cil managed { // ... } .property instance string prefix { .get instance string org.carrot2.util.attribute.BindableAttribute::get_prefix() .set instance void org.carrot2.util.attribute.BindableAttribute::set_prefix(string) } I find the following things interesting: a) prefix() is a virtual override, but is marked private? Is scope limiting (as opposed to widening) possible at the CLR/CLI level? It's quite interesting as to how and where this would apply to (after all, you can always cast to the superclass/interface and then access the method in question, right?). b) C# compiler doesn't seem to accept a method and a property of the same name to coexist. I assume that, again, the rules for CLR/CLI are less restrictive than C# semantics (as it is the case with JVM and Java), but my suspicion is that this confuses Mono and it takes the methods as the first match, as opposed to the property getter, hence the error above. I uploaded a minimal example of the aforementioned problem here: http://ophelia.cs.put.poznan.pl/~dweiss/download/ (the Java class is already compiled into Org.Carrot2.Core.dll, but I can also provide the sources, should they be useful for anything. Full compiler invocation line: gmcs /target:library /reference:Org.Carrot2.Core.dll /reference:IKVM.OpenJDK.Core.dll TypeAdaptersTest.cs or csc /target:library /reference:Org.Carrot2.Core.dll /reference:IKVM.OpenJDK.Core.dll TypeAdaptersTest.cs This isn't urgent my any means, but if anybody finds some time to enlighten me, I'd be very grateful. Dawid |