diff --git a/runtime/ClassLoaderWrapper.cs b/runtime/ClassLoaderWrapper.cs index 3a2db203..34931633 100644 --- a/runtime/ClassLoaderWrapper.cs +++ b/runtime/ClassLoaderWrapper.cs @@ -468,7 +468,15 @@ namespace IKVM.Internal { wrapper = (TypeWrapper)types[name]; } - if(wrapper == null) + if(wrapper != null) + { + if(wrapper.TypeAsTBD != type) + { + string msg = String.Format("\nTypename \"{0}\" is imported from multiple assemblies:\n{1}\n{2}\n", type.FullName, wrapper.Assembly.FullName, type.Assembly.FullName); + JVM.CriticalFailure(msg, null); + } + } + else { if(javaType) { diff --git a/runtime/TypeWrapper.cs b/runtime/TypeWrapper.cs index c7481ed7..e8df9aef 100644 --- a/runtime/TypeWrapper.cs +++ b/runtime/TypeWrapper.cs @@ -1521,6 +1521,35 @@ namespace IKVM.Internal } if(mce != null) { + if(mce.DeclaringType != wrapper) + { + // check the loader constraints + bool error = false; + if(mce.ReturnType != ifmethod.ReturnType) + { + // TODO handle unloadable + error = true; + } + TypeWrapper[] mceparams = mce.GetParameters(); + TypeWrapper[] ifparams = ifmethod.GetParameters(); + for(int i = 0; i < mceparams.Length; i++) + { + if(mceparams[i] != ifparams[i]) + { + // TODO handle unloadable + error = true; + break; + } + } + if(error) + { + MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); + AttributeHelper.HideFromJava(mb); + EmitHelper.Throw(mb.GetILGenerator(), "java.lang.LinkageError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature); + typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod()); + return; + } + } if(mce.IsMirandaMethod && mce.DeclaringType == wrapper) { // Miranda methods already have a methodimpl (if needed) to implement the correct interface method diff --git a/runtime/classpath.cs b/runtime/classpath.cs index 0c616468..f82f6f00 100644 --- a/runtime/classpath.cs +++ b/runtime/classpath.cs @@ -618,16 +618,23 @@ namespace IKVM.NativeCode.java public static string getPackageName(Type type) { - // TODO consider optimizing this (by getting the type name without constructing the TypeWrapper) - string name = ClassLoaderWrapper.GetWrapperFromType(type).Name; - // if we process mscorlib and we encounter a primitive, the name will be null - if(name != null) + string name; + if(type.Assembly is System.Reflection.Emit.AssemblyBuilder) { - int dot = name.LastIndexOf('.'); - if(dot > 0) - { - return name.Substring(0, dot); - } + name = ClassLoaderWrapper.GetWrapperFromType(type).Name; + } + else if(type.Module.IsDefined(typeof(JavaModuleAttribute), false)) + { + name = CompiledTypeWrapper.GetName(type); + } + else + { + name = DotNetTypeWrapper.GetName(type); + } + int dot = name.LastIndexOf('.'); + if(dot > 0) + { + return name.Substring(0, dot); } return null; }