- Type t = null;
- if (declspaces != null) {
- DeclSpace tdecl = declspaces [name] as DeclSpace;
- if (tdecl != null) {
- //
- // Note that this is not:
- //
- // t = tdecl.DefineType ()
- //
- // This is to make it somewhat more useful when a DefineType
- // fails due to problems in nested types (more useful in the sense
- // of fewer misleading error messages)
- //
- tdecl.DefineType ();
- t = tdecl.TypeBuilder;
-
- if (RootContext.EvalMode){
- // Replace the TypeBuilder with a System.Type, as
- // Reflection.Emit fails otherwise (we end up pretty
- // much with Random type definitions later on).
- Type tt = t.Assembly.GetType (t.Name);
- if (tt != null)
- t = tt;
+ IList<TypeSpec> found;
+ if (!types.TryGetValue (name, out found))
+ return null;
+
+ TypeSpec best = null;
+ foreach (var ts in found) {
+ if (ts.Arity == arity) {
+ if (best == null) {
+ best = ts;
+ continue;
+ }
+
+ var pts = best as BuildinTypeSpec;
+ if (pts == null)
+ pts = ts as BuildinTypeSpec;
+
+ if (pts != null) {
+ ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
+ ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
+
+ // TODO: This should use different warning number but we want to be csc compatible
+ ctx.Module.Compiler.Report.Warning (1685, 1, loc,
+ "The predefined type `{0}.{1}' is redefined in the source code. Ignoring the local type definition",
+ pts.Namespace, pts.Name);
+ best = pts;
+ continue;
+ }
+
+ if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
+ ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
+ ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
+ if (silent) {
+ ctx.Module.Compiler.Report.Warning (1685, 1, loc,
+ "The predefined type `{0}' is defined in multiple assemblies. Using definition from `{1}'",
+ ts.GetSignatureForError (), best.MemberDefinition.DeclaringAssembly.Name);
+ } else {
+ ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
+ }
+
+ break;
+ }
+
+ if (best.MemberDefinition.IsImported)
+ best = ts;
+
+ if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly))
+ continue;
+
+ if (silent)
+ continue;
+
+ if (ts.MemberDefinition.IsImported)
+ ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
+
+ ctx.Module.Compiler.Report.Warning (436, 2, loc,
+ "The type `{0}' conflicts with the imported type of same name'. Ignoring the imported type definition",
+ best.GetSignatureForError ());
+ }
+
+ //
+ // Lookup for the best candidate with closest arity match
+ //
+ if (arity < 0) {
+ if (best == null) {
+ best = ts;
+ } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
+ best = ts;