Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / mcs / namespace.cs
1 //
2 // namespace.cs: Tracks namespaces
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Marek Safar (marek.safar@seznam.cz)
7 //
8 // Copyright 2001 Ximian, Inc.
9 // Copyright 2003-2008 Novell, Inc.
10 // Copyright 2011 Xamarin Inc
11 //
12 using System;
13 using System.Collections.Generic;
14 using System.Linq;
15 using Mono.CompilerServices.SymbolWriter;
16
17 namespace Mono.CSharp {
18
19         public class RootNamespace : Namespace {
20
21                 readonly string alias_name;
22                 readonly Dictionary<string, Namespace> all_namespaces;
23
24                 public RootNamespace (string alias_name)
25                         : base (null, String.Empty)
26                 {
27                         this.alias_name = alias_name;
28
29                         all_namespaces = new Dictionary<string, Namespace> ();
30                         all_namespaces.Add ("", this);
31                 }
32
33                 public string Alias {
34                         get {
35                                 return alias_name;
36                         }
37                 }
38
39                 public static void Error_GlobalNamespaceRedefined (Report report, Location loc)
40                 {
41                         report.Error (1681, loc, "The global extern alias cannot be redefined");
42                 }
43
44                 //
45                 // For better error reporting where we try to guess missing using directive
46                 //
47                 public List<string> FindTypeNamespaces (IMemberContext ctx, string name, int arity)
48                 {
49                         List<string> res = null;
50
51                         foreach (var ns in all_namespaces) {
52                                 var type = ns.Value.LookupType (ctx, name, arity, LookupMode.Normal, Location.Null);
53                                 if (type != null) {
54                                         if (res == null)
55                                                 res = new List<string> ();
56
57                                         res.Add (ns.Key);
58                                 }
59                         }
60
61                         return res;
62                 }
63
64                 //
65                 // For better error reporting where compiler tries to guess missing using directive
66                 //
67                 public List<string> FindExtensionMethodNamespaces (IMemberContext ctx, TypeSpec extensionType, string name, int arity)
68                 {
69                         List<string> res = null;
70
71                         foreach (var ns in all_namespaces) {
72                                 var methods = ns.Value.LookupExtensionMethod (ctx, extensionType, name, arity);
73                                 if (methods != null) {
74                                         if (res == null)
75                                                 res = new List<string> ();
76
77                                         res.Add (ns.Key);
78                                 }
79                         }
80
81                         return res;
82                 }
83
84                 public void RegisterNamespace (Namespace child)
85                 {
86                         if (child != this)
87                                 all_namespaces.Add (child.Name, child);
88                 }
89
90                 public bool IsNamespace (string name)
91                 {
92                         return all_namespaces.ContainsKey (name);
93                 }
94
95                 protected void RegisterNamespace (string dotted_name)
96                 {
97                         if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name))
98                                 GetNamespace (dotted_name, true);
99                 }
100
101                 public override string GetSignatureForError ()
102                 {
103                         return alias_name + "::";
104                 }
105         }
106
107         public class GlobalRootNamespace : RootNamespace
108         {
109                 public GlobalRootNamespace ()
110                         : base ("global")
111                 {
112                 }
113         }
114
115         //
116         // Namespace cache for imported and compiled namespaces
117         //
118         // This is an Expression to allow it to be referenced in the
119         // compiler parse/intermediate tree during name resolution.
120         //
121         public class Namespace : FullNamedExpression
122         {
123                 Namespace parent;
124                 string fullname;
125                 protected Dictionary<string, Namespace> namespaces;
126                 protected Dictionary<string, IList<TypeSpec>> types;
127                 List<TypeSpec> extension_method_types;
128                 Dictionary<string, TypeExpr> cached_types;
129                 RootNamespace root;
130                 bool cls_checked;
131
132                 public readonly MemberName MemberName;
133
134                 /// <summary>
135                 ///   Constructor Takes the current namespace and the
136                 ///   name.  This is bootstrapped with parent == null
137                 ///   and name = ""
138                 /// </summary>
139                 public Namespace (Namespace parent, string name)
140                 {
141                         // Expression members.
142                         this.eclass = ExprClass.Namespace;
143                         this.Type = InternalType.Namespace;
144                         this.loc = Location.Null;
145
146                         this.parent = parent;
147
148                         if (parent != null)
149                                 this.root = parent.root;
150                         else
151                                 this.root = this as RootNamespace;
152
153                         if (this.root == null)
154                                 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
155                         
156                         string pname = parent != null ? parent.fullname : "";
157                                 
158                         if (pname == "")
159                                 fullname = name;
160                         else
161                                 fullname = parent.fullname + "." + name;
162
163                         if (fullname == null)
164                                 throw new InternalErrorException ("Namespace has a null fullname");
165
166                         if (parent != null && parent.MemberName != MemberName.Null)
167                                 MemberName = new MemberName (parent.MemberName, name, Location.Null);
168                         else if (name.Length == 0)
169                                 MemberName = MemberName.Null;
170                         else
171                                 MemberName = new MemberName (name, Location.Null);
172
173                         namespaces = new Dictionary<string, Namespace> ();
174                         cached_types = new Dictionary<string, TypeExpr> ();
175
176                         root.RegisterNamespace (this);
177                 }
178
179                 #region Properties
180
181                 /// <summary>
182                 ///   The qualified name of the current namespace
183                 /// </summary>
184                 public string Name {
185                         get { return fullname; }
186                 }
187
188                 /// <summary>
189                 ///   The parent of this namespace, used by the parser to "Pop"
190                 ///   the current namespace declaration
191                 /// </summary>
192                 public Namespace Parent {
193                         get { return parent; }
194                 }
195
196                 #endregion
197
198                 protected override Expression DoResolve (ResolveContext ec)
199                 {
200                         return this;
201                 }
202
203                 public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity, Location loc)
204                 {
205                         var retval = LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc);
206                         if (retval != null) {
207                                 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.Type);
208                                 ErrorIsInaccesible (ctx, retval.GetSignatureForError (), loc);
209                                 return;
210                         }
211
212                         retval = LookupType (ctx, name, -System.Math.Max (1, arity), LookupMode.Probing, loc);
213                         if (retval != null) {
214                                 Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, arity, loc);
215                                 return;
216                         }
217
218                         Namespace ns;
219                         if (arity > 0 && namespaces.TryGetValue (name, out ns)) {
220                                 ns.Error_TypeArgumentsCannotBeUsed (ctx, null, arity, loc);
221                                 return;
222                         }
223
224                         string assembly = null;
225                         string possible_name = fullname + "." + name;
226
227                         // Only assembly unique name should be added
228                         switch (possible_name) {
229                         case "System.Drawing":
230                         case "System.Web.Services":
231                         case "System.Web":
232                         case "System.Data":
233                         case "System.Configuration":
234                         case "System.Data.Services":
235                         case "System.DirectoryServices":
236                         case "System.Json":
237                         case "System.Net.Http":
238                         case "System.Numerics":
239                         case "System.Runtime.Caching":
240                         case "System.ServiceModel":
241                         case "System.Transactions":
242                         case "System.Web.Routing":
243                         case "System.Xml.Linq":
244                         case "System.Xml":
245                                 assembly = possible_name;
246                                 break;
247
248                         case "System.Linq":
249                         case "System.Linq.Expressions":
250                                 assembly = "System.Core";
251                                 break;
252
253                         case "System.Windows.Forms":
254                         case "System.Windows.Forms.Layout":
255                                 assembly = "System.Windows.Name";
256                                 break;
257                         }
258
259                         assembly = assembly == null ? "an" : "`" + assembly + "'";
260
261                         if (this is GlobalRootNamespace) {
262                                 ctx.Module.Compiler.Report.Error (400, loc,
263                                         "The type or namespace name `{0}' could not be found in the global namespace. Are you missing {1} assembly reference?",
264                                         name, assembly);
265                         } else {
266                                 ctx.Module.Compiler.Report.Error (234, loc,
267                                         "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing {2} assembly reference?",
268                                         name, GetSignatureForError (), assembly);
269                         }
270                 }
271
272                 public override string GetSignatureForError ()
273                 {
274                         return fullname;
275                 }
276
277                 public Namespace AddNamespace (MemberName name)
278                 {
279                         Namespace ns_parent;
280                         if (name.Left != null) {
281                                 if (parent != null)
282                                         ns_parent = parent.AddNamespace (name.Left);
283                                 else
284                                         ns_parent = AddNamespace (name.Left);
285                         } else {
286                                 ns_parent = this;
287                         }
288
289                         return ns_parent.TryAddNamespace (name.Basename);
290                 }
291
292                 Namespace TryAddNamespace (string name)
293                 {
294                         Namespace ns;
295
296                         if (!namespaces.TryGetValue (name, out ns)) {
297                                 ns = new Namespace (this, name);
298                                 namespaces.Add (name, ns);
299                         }
300
301                         return ns;
302                 }
303
304                 // TODO: Replace with CreateNamespace where MemberName is created for the method call
305                 public Namespace GetNamespace (string name, bool create)
306                 {
307                         int pos = name.IndexOf ('.');
308
309                         Namespace ns;
310                         string first;
311                         if (pos >= 0)
312                                 first = name.Substring (0, pos);
313                         else
314                                 first = name;
315
316                         if (!namespaces.TryGetValue (first, out ns)) {
317                                 if (!create)
318                                         return null;
319
320                                 ns = new Namespace (this, first);
321                                 namespaces.Add (first, ns);
322                         }
323
324                         if (pos >= 0)
325                                 ns = ns.GetNamespace (name.Substring (pos + 1), create);
326
327                         return ns;
328                 }
329
330                 public IList<TypeSpec> GetAllTypes (string name)
331                 {
332                         IList<TypeSpec> found;
333                         if (types == null || !types.TryGetValue (name, out found))
334                                 return null;
335
336                         return found;
337                 }
338
339                 public TypeExpr LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
340                 {
341                         if (types == null)
342                                 return null;
343
344                         TypeExpr te;
345                         if (arity == 0 && cached_types.TryGetValue (name, out te))
346                                 return te;
347
348                         IList<TypeSpec> found;
349                         if (!types.TryGetValue (name, out found))
350                                 return null;
351
352                         TypeSpec best = null;
353                         foreach (var ts in found) {
354                                 if (ts.Arity == arity) {
355                                         if (best == null) {
356                                                 if ((ts.Modifiers & Modifiers.INTERNAL) != 0 && !ts.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly) && mode != LookupMode.IgnoreAccessibility)
357                                                         continue;
358
359                                                 best = ts;
360                                                 continue;
361                                         }
362
363                                         if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
364                                                 if (mode == LookupMode.Normal) {
365                                                         ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
366                                                         ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
367                                                         ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
368                                                 }
369                                                 break;
370                                         }
371
372                                         if (best.MemberDefinition.IsImported)
373                                                 best = ts;
374
375                                         if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly))
376                                                 continue;
377
378                                         if (mode != LookupMode.Normal)
379                                                 continue;
380
381                                         if (ts.MemberDefinition.IsImported)
382                                                 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
383
384                                         ctx.Module.Compiler.Report.Warning (436, 2, loc,
385                                                 "The type `{0}' conflicts with the imported type of same name'. Ignoring the imported type definition",
386                                                 best.GetSignatureForError ());
387                                 }
388
389                                 //
390                                 // Lookup for the best candidate with the closest arity match
391                                 //
392                                 if (arity < 0) {
393                                         if (best == null) {
394                                                 best = ts;
395                                         } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
396                                                 best = ts;
397                                         }
398                                 }
399                         }
400
401                         if (best == null)
402                                 return null;
403
404                         te = new TypeExpression (best, Location.Null);
405
406                         // TODO MemberCache: Cache more
407                         if (arity == 0 && mode == LookupMode.Normal)
408                                 cached_types.Add (name, te);
409
410                         return te;
411                 }
412
413                 public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
414                 {
415                         var texpr = LookupType (ctx, name, arity, mode, loc);
416
417                         Namespace ns;
418                         if (arity == 0 && namespaces.TryGetValue (name, out ns)) {
419                                 if (texpr == null)
420                                         return ns;
421
422                                 if (mode != LookupMode.Probing) {
423                                         ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type);
424                                         // ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ns.loc, "");
425                                         ctx.Module.Compiler.Report.Warning (437, 2, loc,
426                                                 "The type `{0}' conflicts with the imported namespace `{1}'. Using the definition found in the source file",
427                                                 texpr.GetSignatureForError (), ns.GetSignatureForError ());
428                                 }
429
430                                 if (texpr.Type.MemberDefinition.IsImported)
431                                         return ns;
432                         }
433
434                         return texpr;
435                 }
436
437                 //
438                 // Completes types with the given `prefix'
439                 //
440                 public IEnumerable<string> CompletionGetTypesStartingWith (string prefix)
441                 {
442                         if (types == null)
443                                 return Enumerable.Empty<string> ();
444
445                         var res = from item in types
446                                           where item.Key.StartsWith (prefix) && item.Value.Any (l => (l.Modifiers & Modifiers.PUBLIC) != 0)
447                                           select item.Key;
448
449                         if (namespaces != null)
450                                 res = res.Concat (from item in namespaces where item.Key.StartsWith (prefix) select item.Key);
451
452                         return res;
453                 }
454
455                 // 
456                 // Looks for extension method in this namespace
457                 //
458                 public List<MethodSpec> LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity)
459                 {
460                         if (extension_method_types == null)
461                                 return null;
462
463                         List<MethodSpec> found = null;
464                         for (int i = 0; i < extension_method_types.Count; ++i) {
465                                 var ts = extension_method_types[i];
466
467                                 //
468                                 // When the list was built we didn't know what members the type
469                                 // contains
470                                 //
471                                 if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0) {
472                                         if (extension_method_types.Count == 1) {
473                                                 extension_method_types = null;
474                                                 return found;
475                                         }
476
477                                         extension_method_types.RemoveAt (i--);
478                                         continue;
479                                 }
480
481                                 var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity);
482                                 if (res == null)
483                                         continue;
484
485                                 if (found == null) {
486                                         found = res;
487                                 } else {
488                                         found.AddRange (res);
489                                 }
490                         }
491
492                         return found;
493                 }
494
495                 public void AddType (ModuleContainer module, TypeSpec ts)
496                 {
497                         if (types == null) {
498                                 types = new Dictionary<string, IList<TypeSpec>> (64);
499                         }
500
501                         if (ts.IsClass && ts.Arity == 0) {
502                                 var extension_method_allowed = ts.MemberDefinition.IsImported ? (ts.Modifiers & Modifiers.METHOD_EXTENSION) != 0 : (ts.IsStatic || ts.MemberDefinition.IsPartial);
503                                 if (extension_method_allowed) {
504                                         if (extension_method_types == null)
505                                                 extension_method_types = new List<TypeSpec> ();
506
507                                         extension_method_types.Add (ts);
508                                 }
509                         }
510
511                         var name = ts.Name;
512                         IList<TypeSpec> existing;
513                         if (types.TryGetValue (name, out existing)) {
514                                 TypeSpec better_type;
515                                 TypeSpec found;
516                                 if (existing.Count == 1) {
517                                         found = existing[0];
518                                         if (ts.Arity == found.Arity) {
519                                                 better_type = IsImportedTypeOverride (module, ts, found);
520                                                 if (better_type == found)
521                                                         return;
522
523                                                 if (better_type != null) {
524                                                         existing [0] = better_type;
525                                                         return;
526                                                 }
527                                         }
528
529                                         existing = new List<TypeSpec> ();
530                                         existing.Add (found);
531                                         types[name] = existing;
532                                 } else {
533                                         for (int i = 0; i < existing.Count; ++i) {
534                                                 found = existing[i];
535                                                 if (ts.Arity != found.Arity)
536                                                         continue;
537
538                                                 better_type = IsImportedTypeOverride (module, ts, found);
539                                                 if (better_type == found)
540                                                         return;
541
542                                                 if (better_type != null) {
543                                                         existing.RemoveAt (i);
544                                                         --i;
545                                                         continue;
546                                                 }
547                                         }
548                                 }
549
550                                 existing.Add (ts);
551                         } else {
552                                 types.Add (name, new TypeSpec[] { ts });
553                         }
554                 }
555
556                 //
557                 // We import any types but in the situation there are same types
558                 // but one has better visibility (either public or internal with friend)
559                 // the less visible type is removed from the namespace cache
560                 //
561                 public static TypeSpec IsImportedTypeOverride (ModuleContainer module, TypeSpec ts, TypeSpec found)
562                 {
563                         var ts_accessible = (ts.Modifiers & Modifiers.PUBLIC) != 0 || ts.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);
564                         var found_accessible = (found.Modifiers & Modifiers.PUBLIC) != 0 || found.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);
565
566                         if (ts_accessible && !found_accessible)
567                                 return ts;
568
569                         // found is better always better for accessible or inaccessible ts
570                         if (!ts_accessible)
571                                 return found;
572
573                         return null;
574                 }
575
576                 public void RemoveContainer (TypeContainer tc)
577                 {
578                         types.Remove (tc.Basename);
579                         cached_types.Remove (tc.Basename);
580                 }
581
582                 public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
583                 {
584                         return this;
585                 }
586
587                 public void SetBuiltinType (BuiltinTypeSpec pts)
588                 {
589                         var found = types[pts.Name];
590                         cached_types.Remove (pts.Name);
591                         if (found.Count == 1) {
592                                 types[pts.Name][0] = pts;
593                         } else {
594                                 throw new NotImplementedException ();
595                         }
596                 }
597
598                 public void VerifyClsCompliance ()
599                 {
600                         if (types == null || cls_checked)
601                                 return;
602
603                         cls_checked = true;
604
605                         // TODO: This is quite ugly way to check for CLS compliance at namespace level
606
607                         var locase_types = new Dictionary<string, List<TypeSpec>> (StringComparer.OrdinalIgnoreCase);
608                         foreach (var tgroup in types.Values) {
609                                 foreach (var tm in tgroup) {
610                                         if ((tm.Modifiers & Modifiers.PUBLIC) == 0 || !tm.IsCLSCompliant ())
611                                                 continue;
612
613                                         List<TypeSpec> found;
614                                         if (!locase_types.TryGetValue (tm.Name, out found)) {
615                                                 found = new List<TypeSpec> ();
616                                                 locase_types.Add (tm.Name, found);
617                                         }
618
619                                         found.Add (tm);
620                                 }
621                         }
622
623                         foreach (var locase in locase_types.Values) {
624                                 if (locase.Count < 2)
625                                         continue;
626
627                                 bool all_same = true;
628                                 foreach (var notcompliant in locase) {
629                                         all_same = notcompliant.Name == locase[0].Name;
630                                         if (!all_same)
631                                                 break;
632                                 }
633
634                                 if (all_same)
635                                         continue;
636
637                                 TypeContainer compiled = null;
638                                 foreach (var notcompliant in locase) {
639                                         if (!notcompliant.MemberDefinition.IsImported) {
640                                                 if (compiled != null)
641                                                         compiled.Compiler.Report.SymbolRelatedToPreviousError (compiled);
642
643                                                 compiled = notcompliant.MemberDefinition as TypeContainer;
644                                         } else {
645                                                 compiled.Compiler.Report.SymbolRelatedToPreviousError (notcompliant);
646                                         }
647                                 }
648
649                                 compiled.Compiler.Report.Warning (3005, 1, compiled.Location,
650                                         "Identifier `{0}' differing only in case is not CLS-compliant", compiled.GetSignatureForError ());
651                         }
652                 }
653
654                 public override string ToString ()
655                 {
656                         return Name;
657                 }
658         }
659
660         public class CompilationSourceFile : NamespaceContainer
661         {
662                 readonly SourceFile file;
663                 CompileUnitEntry comp_unit;
664                 Dictionary<string, SourceFile> include_files;
665                 Dictionary<string, bool> conditionals;
666
667                 public CompilationSourceFile (ModuleContainer parent, SourceFile sourceFile)
668                         : this (parent)
669                 {
670                         this.file = sourceFile;
671                 }
672
673                 public CompilationSourceFile (ModuleContainer parent)
674                         : base (parent)
675                 {
676                 }
677
678                 public CompileUnitEntry SymbolUnitEntry {
679                         get {
680                                 return comp_unit;
681                         }
682                 }
683
684                 public string FileName {
685                         get {
686                                 return file.Name;
687                         }
688                 }
689
690                 public SourceFile SourceFile {
691                         get {
692                                 return file;
693                         }
694                 }
695
696                 public void AddIncludeFile (SourceFile file)
697                 {
698                         if (file == this.file)
699                                 return;
700
701                         if (include_files == null)
702                                 include_files = new Dictionary<string, SourceFile> ();
703
704                         if (!include_files.ContainsKey (file.FullPathName))
705                                 include_files.Add (file.FullPathName, file);
706                 }
707
708                 public void AddDefine (string value)
709                 {
710                         if (conditionals == null)
711                                 conditionals = new Dictionary<string, bool> (2);
712
713                         conditionals[value] = true;
714                 }
715
716                 public void AddUndefine (string value)
717                 {
718                         if (conditionals == null)
719                                 conditionals = new Dictionary<string, bool> (2);
720
721                         conditionals[value] = false;
722                 }
723
724                 public override void PrepareEmit ()
725                 {
726                         var sw = Module.DeclaringAssembly.SymbolWriter;
727                         if (sw != null) {
728                                 CreateUnitSymbolInfo (sw);
729                         }
730
731                         base.PrepareEmit ();
732                 }
733
734                 //
735                 // Creates symbol file index in debug symbol file
736                 //
737                 void CreateUnitSymbolInfo (MonoSymbolFile symwriter)
738                 {
739                         var si = file.CreateSymbolInfo (symwriter);
740                         comp_unit = new CompileUnitEntry (symwriter, si);;
741
742                         if (include_files != null) {
743                                 foreach (SourceFile include in include_files.Values) {
744                                         si = include.CreateSymbolInfo (symwriter);
745                                         comp_unit.AddFile (si);
746                                 }
747                         }
748                 }
749
750                 public bool IsConditionalDefined (string value)
751                 {
752                         if (conditionals != null) {
753                                 bool res;
754                                 if (conditionals.TryGetValue (value, out res))
755                                         return res;
756
757                                 // When conditional was undefined
758                                 if (conditionals.ContainsKey (value))
759                                         return false;
760                         }
761
762                         return Compiler.Settings.IsConditionalSymbolDefined (value);
763                 }
764         }
765
766
767         //
768         // Namespace block as created by the parser
769         //
770         public class NamespaceContainer : TypeContainer, IMemberContext
771         {
772                 static readonly Namespace[] empty_namespaces = new Namespace[0];
773
774                 readonly Namespace ns;
775
776                 public new readonly NamespaceContainer Parent;
777
778                 List<UsingNamespace> clauses;
779
780                 // Used by parsed to check for parser errors
781                 public bool DeclarationFound;
782
783                 Namespace[] namespace_using_table;
784                 Dictionary<string, UsingAliasNamespace> aliases;
785
786                 public NamespaceContainer (MemberName name, NamespaceContainer parent)
787                         : base (parent, name, null, MemberKind.Namespace)
788                 {
789                         this.Parent = parent;
790                         this.ns = parent.NS.AddNamespace (name);
791
792                         containers = new List<TypeContainer> ();
793                 }
794
795                 protected NamespaceContainer (ModuleContainer parent)
796                         : base (parent, null, null, MemberKind.Namespace)
797                 {
798                         ns = parent.GlobalRootNamespace;
799                         containers = new List<TypeContainer> (2);
800                 }
801
802                 #region Properties
803
804                 public override AttributeTargets AttributeTargets {
805                         get {
806                                 throw new NotSupportedException ();
807                         }
808                 }
809
810                 public override string DocCommentHeader {
811                         get {
812                                 throw new NotSupportedException ();
813                         }
814                 }
815
816                 public Namespace NS {
817                         get {
818                                 return ns;
819                         }
820                 }
821
822                 public List<UsingNamespace> Usings {
823                         get {
824                                 return clauses;
825                         }
826                 }
827
828                 public override string[] ValidAttributeTargets {
829                         get {
830                                 throw new NotSupportedException ();
831                         }
832                 }
833
834                 #endregion
835
836                 public void AddUsing (UsingNamespace un)
837                 {
838                         if (DeclarationFound){
839                                 Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
840                         }
841
842                         if (clauses == null)
843                                 clauses = new List<UsingNamespace> ();
844
845                         clauses.Add (un);
846                 }
847
848                 public void AddUsing (UsingAliasNamespace un)
849                 {
850                         if (DeclarationFound){
851                                 Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
852                         }
853
854                         AddAlias (un);
855                 }
856
857                 void AddAlias (UsingAliasNamespace un)
858                 {
859                         if (clauses == null) {
860                                 clauses = new List<UsingNamespace> ();
861                         } else {
862                                 foreach (var entry in clauses) {
863                                         var a = entry as UsingAliasNamespace;
864                                         if (a != null && a.Alias.Value == un.Alias.Value) {
865                                                 Compiler.Report.SymbolRelatedToPreviousError (a.Location, "");
866                                                 Compiler.Report.Error (1537, un.Location,
867                                                         "The using alias `{0}' appeared previously in this namespace", un.Alias.Value);
868                                         }
869                                 }
870                         }
871
872                         clauses.Add (un);
873                 }
874
875                 public override void AddPartial (TypeDefinition next_part)
876                 {
877                         var existing = ns.LookupType (this, next_part.MemberName.Name, next_part.MemberName.Arity, LookupMode.Probing, Location.Null);
878                         var td = existing != null ? existing.Type.MemberDefinition as TypeDefinition : null;
879                         AddPartial (next_part, td);
880                 }
881
882                 public override void AddTypeContainer (TypeContainer tc)
883                 {
884                         string name = tc.Basename;
885
886                         var mn = tc.MemberName;
887                         while (mn.Left != null) {
888                                 mn = mn.Left;
889                                 name = mn.Name;
890                         }
891
892                         var names_container = Parent == null ? Module : (TypeContainer) this;
893
894                         MemberCore mc;
895                         if (names_container.DefinedNames.TryGetValue (name, out mc)) {
896                                 if (tc is NamespaceContainer && mc is NamespaceContainer) {
897                                         containers.Add (tc);
898                                         return;
899                                 }
900
901                                 Report.SymbolRelatedToPreviousError (mc);
902                                 if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (tc is ClassOrStruct || tc is Interface)) {
903                                         Error_MissingPartialModifier (tc);
904                                 } else {
905                                         Report.Error (101, tc.Location, "The namespace `{0}' already contains a definition for `{1}'",
906                                                 GetSignatureForError (), mn.GetSignatureForError ());
907                                 }
908                         } else {
909                                 names_container.DefinedNames.Add (name, tc);
910
911                                 var tdef = tc.PartialContainer;
912                                 if (tdef != null) {
913                                         //
914                                         // Same name conflict in different namespace containers
915                                         //
916                                         var conflict = ns.GetAllTypes (name);
917                                         if (conflict != null) {
918                                                 foreach (var e in conflict) {
919                                                         if (e.Arity == mn.Arity) {
920                                                                 mc = (MemberCore) e.MemberDefinition;
921                                                                 break;
922                                                         }
923                                                 }
924                                         }
925
926                                         if (mc != null) {
927                                                 Report.SymbolRelatedToPreviousError (mc);
928                                                 Report.Error (101, tc.Location, "The namespace `{0}' already contains a definition for `{1}'",
929                                                         GetSignatureForError (), mn.GetSignatureForError ());
930                                         } else {
931                                                 ns.AddType (Module, tdef.Definition);
932                                         }
933                                 }
934                         }
935
936                         base.AddTypeContainer (tc);
937                 }
938
939                 public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
940                 {
941                         throw new NotSupportedException ();
942                 }
943
944                 public override void EmitContainer ()
945                 {
946                         VerifyClsCompliance ();
947
948                         base.EmitContainer ();
949                 }
950
951                 public ExtensionMethodCandidates LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity, int position)
952                 {
953                         //
954                         // Here we try to resume the search for extension method at the point
955                         // where the last bunch of candidates was found. It's more tricky than
956                         // it seems as we have to check both namespace containers and namespace
957                         // in correct order.
958                         //
959                         // Consider:
960                         // 
961                         // namespace A {
962                         //      using N1;
963                         //  namespace B.C.D {
964                         //              <our first search found candidates in A.B.C.D
965                         //  }
966                         // }
967                         //
968                         // In the example above namespace A.B.C.D, A.B.C and A.B have to be
969                         // checked before we hit A.N1 using
970                         //
971                         ExtensionMethodCandidates candidates;
972                         var container = this;
973                         do {
974                                 candidates = container.LookupExtensionMethodCandidates (invocationContext, extensionType, name, arity, ref position);
975                                 if (candidates != null || container.MemberName == null)
976                                         return candidates;
977
978                                 var container_ns = container.ns.Parent;
979                                 var mn = container.MemberName.Left;
980                                 int already_checked = position - 2;
981                                 while (already_checked-- > 0) {
982                                         mn = mn.Left;
983                                         container_ns = container_ns.Parent;
984                                 }
985
986                                 while (mn != null) {
987                                         ++position;
988
989                                         var methods = container_ns.LookupExtensionMethod (invocationContext, extensionType, name, arity);
990                                         if (methods != null) {
991                                                 return new ExtensionMethodCandidates (invocationContext, methods, container, position);
992                                         }
993
994                                         mn = mn.Left;
995                                         container_ns = container_ns.Parent;
996                                 }
997
998                                 position = 0;
999                                 container = container.Parent;
1000                         } while (container != null);
1001
1002                         return null;
1003                 }
1004
1005                 ExtensionMethodCandidates LookupExtensionMethodCandidates (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity, ref int position)
1006                 {
1007                         List<MethodSpec> candidates = null;
1008
1009                         if (position == 0) {
1010                                 ++position;
1011
1012                                 candidates = ns.LookupExtensionMethod (invocationContext, extensionType, name, arity);
1013                                 if (candidates != null) {
1014                                         return new ExtensionMethodCandidates (invocationContext, candidates, this, position);
1015                                 }
1016                         }
1017
1018                         if (position == 1) {
1019                                 ++position;
1020
1021                                 foreach (Namespace n in namespace_using_table) {
1022                                         var a = n.LookupExtensionMethod (invocationContext, extensionType, name, arity);
1023                                         if (a == null)
1024                                                 continue;
1025
1026                                         if (candidates == null)
1027                                                 candidates = a;
1028                                         else
1029                                                 candidates.AddRange (a);
1030                                 }
1031
1032                                 if (candidates != null)
1033                                         return new ExtensionMethodCandidates (invocationContext, candidates, this, position);
1034                         }
1035
1036                         return null;
1037                 }
1038
1039                 public override FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
1040                 {
1041                         //
1042                         // Only simple names (no dots) will be looked up with this function
1043                         //
1044                         FullNamedExpression resolved;
1045                         for (NamespaceContainer container = this; container != null; container = container.Parent) {
1046                                 resolved = container.Lookup (name, arity, mode, loc);
1047                                 if (resolved != null || container.MemberName == null)
1048                                         return resolved;
1049
1050                                 var container_ns = container.ns.Parent;
1051                                 var mn = container.MemberName.Left;
1052                                 while (mn != null) {
1053                                         resolved = container_ns.LookupTypeOrNamespace (this, name, arity, mode, loc);
1054                                         if (resolved != null)
1055                                                 return resolved;
1056
1057                                         mn = mn.Left;
1058                                         container_ns = container_ns.Parent;
1059                                 }
1060                         }
1061
1062                         return null;
1063                 }
1064
1065                 public override void GetCompletionStartingWith (string prefix, List<string> results)
1066                 {
1067                         foreach (var un in Usings) {
1068                                 if (un.Alias != null)
1069                                         continue;
1070
1071                                 var name = un.NamespaceExpression.Name;
1072                                 if (name.StartsWith (prefix))
1073                                         results.Add (name);
1074                         }
1075
1076
1077                         IEnumerable<string> all = Enumerable.Empty<string> ();
1078
1079                         foreach (Namespace using_ns in namespace_using_table) {
1080                                 if (prefix.StartsWith (using_ns.Name)) {
1081                                         int ld = prefix.LastIndexOf ('.');
1082                                         if (ld != -1) {
1083                                                 string rest = prefix.Substring (ld + 1);
1084
1085                                                 all = all.Concat (using_ns.CompletionGetTypesStartingWith (rest));
1086                                         }
1087                                 }
1088                                 all = all.Concat (using_ns.CompletionGetTypesStartingWith (prefix));
1089                         }
1090
1091                         results.AddRange (all);
1092
1093                         base.GetCompletionStartingWith (prefix, results);
1094                 }
1095
1096                 
1097                 //
1098                 // Looks-up a alias named @name in this and surrounding namespace declarations
1099                 //
1100                 public FullNamedExpression LookupExternAlias (string name)
1101                 {
1102                         if (aliases == null)
1103                                 return null;
1104
1105                         UsingAliasNamespace uan;
1106                         if (aliases.TryGetValue (name, out uan) && uan is UsingExternAlias)
1107                                 return uan.ResolvedExpression;
1108
1109                         return null;
1110                 }
1111                 
1112                 //
1113                 // Looks-up a alias named @name in this and surrounding namespace declarations
1114                 //
1115                 public override FullNamedExpression LookupNamespaceAlias (string name)
1116                 {
1117                         for (NamespaceContainer n = this; n != null; n = n.Parent) {
1118                                 if (n.aliases == null)
1119                                         continue;
1120
1121                                 UsingAliasNamespace uan;
1122                                 if (n.aliases.TryGetValue (name, out uan))
1123                                         return uan.ResolvedExpression;
1124                         }
1125
1126                         return null;
1127                 }
1128
1129                 FullNamedExpression Lookup (string name, int arity, LookupMode mode, Location loc)
1130                 {
1131                         //
1132                         // Check whether it's in the namespace.
1133                         //
1134                         FullNamedExpression fne = ns.LookupTypeOrNamespace (this, name, arity, mode, loc);
1135
1136                         //
1137                         // Check aliases. 
1138                         //
1139                         if (aliases != null && arity == 0) {
1140                                 UsingAliasNamespace uan;
1141                                 if (aliases.TryGetValue (name, out uan)) {
1142                                         if (fne != null) {
1143                                                 // TODO: Namespace has broken location
1144                                                 //Report.SymbolRelatedToPreviousError (fne.Location, null);
1145                                                 Compiler.Report.SymbolRelatedToPreviousError (uan.Location, null);
1146                                                 Compiler.Report.Error (576, loc,
1147                                                         "Namespace `{0}' contains a definition with same name as alias `{1}'",
1148                                                         GetSignatureForError (), name);
1149                                         }
1150
1151                                         return uan.ResolvedExpression;
1152                                 }
1153                         }
1154
1155                         if (fne != null)
1156                                 return fne;
1157
1158                         //
1159                         // Lookup can be called before the namespace is defined from different namespace using alias clause
1160                         //
1161                         if (namespace_using_table == null) {
1162                                 DoDefineNamespace ();
1163                         }
1164
1165                         //
1166                         // Check using entries.
1167                         //
1168                         FullNamedExpression match = null;
1169                         foreach (Namespace using_ns in namespace_using_table) {
1170                                 //
1171                                 // A using directive imports only types contained in the namespace, it
1172                                 // does not import any nested namespaces
1173                                 //
1174                                 fne = using_ns.LookupType (this, name, arity, mode, loc);
1175                                 if (fne == null)
1176                                         continue;
1177
1178                                 if (match == null) {
1179                                         match = fne;
1180                                         continue;
1181                                 }
1182
1183                                 // Prefer types over namespaces
1184                                 var texpr_fne = fne as TypeExpr;
1185                                 var texpr_match = match as TypeExpr;
1186                                 if (texpr_fne != null && texpr_match == null) {
1187                                         match = fne;
1188                                         continue;
1189                                 } else if (texpr_fne == null) {
1190                                         continue;
1191                                 }
1192
1193                                 // It can be top level accessibility only
1194                                 var better = Namespace.IsImportedTypeOverride (Module, texpr_match.Type, texpr_fne.Type);
1195                                 if (better == null) {
1196                                         if (mode == LookupMode.Normal) {
1197                                                 Compiler.Report.SymbolRelatedToPreviousError (texpr_match.Type);
1198                                                 Compiler.Report.SymbolRelatedToPreviousError (texpr_fne.Type);
1199                                                 Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
1200                                                         name, texpr_match.GetSignatureForError (), texpr_fne.GetSignatureForError ());
1201                                         }
1202
1203                                         return match;
1204                                 }
1205
1206                                 if (better == texpr_fne.Type)
1207                                         match = texpr_fne;
1208                         }
1209
1210                         return match;
1211                 }
1212
1213                 protected override void DefineNamespace ()
1214                 {
1215                         if (namespace_using_table == null)
1216                                 DoDefineNamespace ();
1217
1218                         base.DefineNamespace ();
1219                 }
1220
1221                 void DoDefineNamespace ()
1222                 {
1223                         namespace_using_table = empty_namespaces;
1224
1225                         if (clauses != null) {
1226                                 var list = new List<Namespace> (clauses.Count);
1227                                 bool post_process_using_aliases = false;
1228
1229                                 for (int i = 0; i < clauses.Count; ++i) {
1230                                         var entry = clauses[i];
1231
1232                                         if (entry.Alias != null) {
1233                                                 if (aliases == null)
1234                                                         aliases = new Dictionary<string, UsingAliasNamespace> ();
1235
1236                                                 //
1237                                                 // Aliases are not available when resolving using section
1238                                                 // except extern aliases
1239                                                 //
1240                                                 if (entry is UsingExternAlias) {
1241                                                         entry.Define (this);
1242                                                         if (entry.ResolvedExpression != null)
1243                                                                 aliases.Add (entry.Alias.Value, (UsingExternAlias) entry);
1244
1245                                                         clauses.RemoveAt (i--);
1246                                                 } else {
1247                                                         post_process_using_aliases = true;
1248                                                 }
1249
1250                                                 continue;
1251                                         }
1252
1253                                         entry.Define (this);
1254
1255                                         //
1256                                         // It's needed for repl only, when using clause cannot be resolved don't hold it in
1257                                         // global list which is resolved for each evaluation
1258                                         //
1259                                         if (entry.ResolvedExpression == null) {
1260                                                 clauses.RemoveAt (i--);
1261                                                 continue;
1262                                         }
1263
1264                                         Namespace using_ns = entry.ResolvedExpression as Namespace;
1265                                         if (using_ns == null)
1266                                                 continue;
1267
1268                                         if (list.Contains (using_ns)) {
1269                                                 // Ensure we don't report the warning multiple times in repl
1270                                                 clauses.RemoveAt (i--);
1271
1272                                                 Compiler.Report.Warning (105, 3, entry.Location,
1273                                                         "The using directive for `{0}' appeared previously in this namespace", using_ns.GetSignatureForError ());
1274                                         } else {
1275                                                 list.Add (using_ns);
1276                                         }
1277                                 }
1278
1279                                 namespace_using_table = list.ToArray ();
1280
1281                                 if (post_process_using_aliases) {
1282                                         for (int i = 0; i < clauses.Count; ++i) {
1283                                                 var entry = clauses[i];
1284                                                 if (entry.Alias != null) {
1285                                                         entry.Define (this);
1286                                                         if (entry.ResolvedExpression != null) {
1287                                                                 aliases.Add (entry.Alias.Value, (UsingAliasNamespace) entry);
1288                                                         }
1289
1290                                                         clauses.RemoveAt (i--);
1291                                                 }
1292                                         }
1293                                 }
1294                         }
1295                 }
1296
1297                 public void EnableRedefinition ()
1298                 {
1299                         is_defined = false;
1300                         namespace_using_table = null;
1301                 }
1302
1303                 internal override void GenerateDocComment (DocumentationBuilder builder)
1304                 {
1305                         if (containers != null) {
1306                                 foreach (var tc in containers)
1307                                         tc.GenerateDocComment (builder);
1308                         }
1309                 }
1310
1311                 public override string GetSignatureForError ()
1312                 {
1313                         return MemberName == null ? "global::" : base.GetSignatureForError ();
1314                 }
1315
1316                 public override void RemoveContainer (TypeContainer cont)
1317                 {
1318                         base.RemoveContainer (cont);
1319                         NS.RemoveContainer (cont);
1320                 }
1321
1322                 protected override bool VerifyClsCompliance ()
1323                 {
1324                         if (Module.IsClsComplianceRequired ()) {
1325                                 if (MemberName != null && MemberName.Name[0] == '_') {
1326                                         Warning_IdentifierNotCompliant ();
1327                                 }
1328
1329                                 ns.VerifyClsCompliance ();
1330                                 return true;
1331                         }
1332
1333                         return false;
1334                 }
1335         }
1336
1337         public class UsingNamespace
1338         {
1339                 readonly ATypeNameExpression expr;
1340                 readonly Location loc;
1341                 protected FullNamedExpression resolved;
1342
1343                 public UsingNamespace (ATypeNameExpression expr, Location loc)
1344                 {
1345                         this.expr = expr;
1346                         this.loc = loc;
1347                 }
1348
1349                 #region Properties
1350
1351                 public virtual SimpleMemberName Alias {
1352                         get {
1353                                 return null;
1354                         }
1355                 }
1356
1357                 public Location Location {
1358                         get {
1359                                 return loc;
1360                         }
1361                 }
1362
1363                 public ATypeNameExpression NamespaceExpression  {
1364                         get {
1365                                 return expr;
1366                         }
1367                 }
1368
1369                 public FullNamedExpression ResolvedExpression {
1370                         get {
1371                                 return resolved;
1372                         }
1373                 }
1374
1375                 #endregion
1376
1377                 public string GetSignatureForError ()
1378                 {
1379                         return expr.GetSignatureForError ();
1380                 }
1381
1382                 public virtual void Define (NamespaceContainer ctx)
1383                 {
1384                         resolved = expr.ResolveAsTypeOrNamespace (ctx);
1385                         var ns = resolved as Namespace;
1386                         if (ns == null) {
1387                                 if (resolved != null) {
1388                                         ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type);
1389                                         ctx.Module.Compiler.Report.Error (138, Location,
1390                                                 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
1391                                                 GetSignatureForError ());
1392                                 }
1393                         }
1394                 }
1395
1396                 public override string ToString()
1397                 {
1398                         return resolved.ToString();
1399                 }
1400         }
1401
1402         public class UsingExternAlias : UsingAliasNamespace
1403         {
1404                 public UsingExternAlias (SimpleMemberName alias, Location loc)
1405                         : base (alias, null, loc)
1406                 {
1407                 }
1408
1409                 public override void Define (NamespaceContainer ctx)
1410                 {
1411                         resolved = ctx.Module.GetRootNamespace (Alias.Value);
1412                         if (resolved == null) {
1413                                 ctx.Module.Compiler.Report.Error (430, Location,
1414                                         "The extern alias `{0}' was not specified in -reference option",
1415                                         Alias.Value);
1416                         }
1417                 }
1418         }
1419
1420         public class UsingAliasNamespace : UsingNamespace
1421         {
1422                 readonly SimpleMemberName alias;
1423
1424                 public struct AliasContext : IMemberContext
1425                 {
1426                         readonly NamespaceContainer ns;
1427
1428                         public AliasContext (NamespaceContainer ns)
1429                         {
1430                                 this.ns = ns;
1431                         }
1432
1433                         public TypeSpec CurrentType {
1434                                 get {
1435                                         return null;
1436                                 }
1437                         }
1438
1439                         public TypeParameters CurrentTypeParameters {
1440                                 get {
1441                                         return null;
1442                                 }
1443                         }
1444
1445                         public MemberCore CurrentMemberDefinition {
1446                                 get {
1447                                         return null;
1448                                 }
1449                         }
1450
1451                         public bool IsObsolete {
1452                                 get {
1453                                         return false;
1454                                 }
1455                         }
1456
1457                         public bool IsUnsafe {
1458                                 get {
1459                                         throw new NotImplementedException ();
1460                                 }
1461                         }
1462
1463                         public bool IsStatic {
1464                                 get {
1465                                         throw new NotImplementedException ();
1466                                 }
1467                         }
1468
1469                         public ModuleContainer Module {
1470                                 get {
1471                                         return ns.Module;
1472                                 }
1473                         }
1474
1475                         public string GetSignatureForError ()
1476                         {
1477                                 throw new NotImplementedException ();
1478                         }
1479
1480                         public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
1481                         {
1482                                 return null;
1483                         }
1484
1485                         public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
1486                         {
1487                                 var fne = ns.NS.LookupTypeOrNamespace (ns, name, arity, mode, loc);
1488                                 if (fne != null)
1489                                         return fne;
1490
1491                                 //
1492                                 // Only extern aliases are allowed in this context
1493                                 //
1494                                 fne = ns.LookupExternAlias (name);
1495                                 if (fne != null || ns.MemberName == null)
1496                                         return fne;
1497
1498                                 var container_ns = ns.NS.Parent;
1499                                 var mn = ns.MemberName.Left;
1500                                 while (mn != null) {
1501                                         fne = container_ns.LookupTypeOrNamespace (this, name, arity, mode, loc);
1502                                         if (fne != null)
1503                                                 return fne;
1504
1505                                         mn = mn.Left;
1506                                         container_ns = container_ns.Parent;
1507                                 }
1508
1509                                 if (ns.Parent != null)
1510                                         return ns.Parent.LookupNamespaceOrType (name, arity, mode, loc);
1511
1512                                 return null;
1513                         }
1514
1515                         public FullNamedExpression LookupNamespaceAlias (string name)
1516                         {
1517                                 return ns.LookupNamespaceAlias (name);
1518                         }
1519                 }
1520
1521                 public UsingAliasNamespace (SimpleMemberName alias, ATypeNameExpression expr, Location loc)
1522                         : base (expr, loc)
1523                 {
1524                         this.alias = alias;
1525                 }
1526
1527                 public override SimpleMemberName Alias {
1528                         get {
1529                                 return alias;
1530                         }
1531                 }
1532
1533                 public override void Define (NamespaceContainer ctx)
1534                 {
1535                         //
1536                         // The namespace-or-type-name of a using-alias-directive is resolved as if
1537                         // the immediately containing compilation unit or namespace body had no
1538                         // using-directives. A using-alias-directive may however be affected
1539                         // by extern-alias-directives in the immediately containing compilation
1540                         // unit or namespace body
1541                         //
1542                         // We achieve that by introducing alias-context which redirect any local
1543                         // namespace or type resolve calls to parent namespace
1544                         //
1545                         resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx));
1546                 }
1547         }
1548 }