[mcs] C# 7 tuple (foundation only).
[mono.git] / mcs / mcs / namespace.cs
index 02f17ccfc4b8978b9e51c1d7d2d9a566660fdd5d..3314ca2d48c24d8341e6c44faf7523343d0fc182 100644 (file)
@@ -624,8 +624,8 @@ namespace Mono.CSharp {
                        if (include_files == null)
                                include_files = new Dictionary<string, SourceFile> ();
 
-                       if (!include_files.ContainsKey (file.FullPathName))
-                               include_files.Add (file.FullPathName, file);
+                       if (!include_files.ContainsKey (file.OriginalFullPathName))
+                               include_files.Add (file.OriginalFullPathName, file);
                }
 
                public void AddDefine (string value)
@@ -648,7 +648,7 @@ namespace Mono.CSharp {
                {
                        var sw = Module.DeclaringAssembly.SymbolWriter;
                        if (sw != null) {
-                               CreateUnitSymbolInfo (sw);
+                               CreateUnitSymbolInfo (sw, Compiler.Settings.PathMap);
                        }
 
                        base.PrepareEmit ();
@@ -657,14 +657,14 @@ namespace Mono.CSharp {
                //
                // Creates symbol file index in debug symbol file
                //
-               void CreateUnitSymbolInfo (MonoSymbolFile symwriter)
+               void CreateUnitSymbolInfo (MonoSymbolFile symwriter, List<KeyValuePair<string, string>> pathMap)
                {
-                       var si = file.CreateSymbolInfo (symwriter);
+                       var si = file.CreateSymbolInfo (symwriter, pathMap);
                        comp_unit = new CompileUnitEntry (symwriter, si);
 
                        if (include_files != null) {
                                foreach (SourceFile include in include_files.Values) {
-                                       si = include.CreateSymbolInfo (symwriter);
+                                       si = include.CreateSymbolInfo (symwriter, pathMap);
                                        comp_unit.AddFile (si);
                                }
                        }
@@ -841,7 +841,7 @@ namespace Mono.CSharp {
                                        //
                                        // Same name conflict in different namespace containers
                                        //
-                                       var conflict = ns.GetAllTypes (name);
+                                       var conflict = ns.GetAllTypes (mn.Name);
                                        if (conflict != null) {
                                                foreach (var e in conflict) {
                                                        if (e.Arity == mn.Arity) {
@@ -1064,8 +1064,12 @@ namespace Mono.CSharp {
                                        continue;
 
                                UsingAliasNamespace uan;
-                               if (n.aliases.TryGetValue (name, out uan))
+                               if (n.aliases.TryGetValue (name, out uan)) {
+                                       if (uan.ResolvedExpression == null)
+                                               uan.Define (n);
+
                                        return uan.ResolvedExpression;
+                               }
                        }
 
                        return null;
@@ -1093,6 +1097,9 @@ namespace Mono.CSharp {
                                                        GetSignatureForError (), name);
                                        }
 
+                                       if (uan.ResolvedExpression == null)
+                                               uan.Define (this);
+
                                        return uan.ResolvedExpression;
                                }
                        }
@@ -1140,10 +1147,7 @@ namespace Mono.CSharp {
                                var better = Namespace.IsImportedTypeOverride (Module, texpr_match.Type, texpr_fne.Type);
                                if (better == null) {
                                        if (mode == LookupMode.Normal) {
-                                               Compiler.Report.SymbolRelatedToPreviousError (texpr_match.Type);
-                                               Compiler.Report.SymbolRelatedToPreviousError (texpr_fne.Type);
-                                               Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
-                                                       name, texpr_match.GetSignatureForError (), texpr_fne.GetSignatureForError ());
+                                               Error_AmbiguousReference (name, texpr_match, texpr_fne, loc);
                                        }
 
                                        return match;
@@ -1153,9 +1157,36 @@ namespace Mono.CSharp {
                                        match = texpr_fne;
                        }
 
+                       if (types_using_table != null && (mode & LookupMode.IgnoreStaticUsing) == 0) {
+                               foreach (var using_type in types_using_table) {
+                                       var type = MemberCache.FindNestedType (using_type, name, arity, true);
+                                       if (type == null)
+                                               continue;
+                                       
+                                       fne = new TypeExpression (type, loc);
+                                       if (match == null) {
+                                               match = fne;
+                                               continue;
+                                       }
+
+                                       if (mode == LookupMode.Normal) {
+                                               Error_AmbiguousReference (name, match, fne, loc);
+                                       }
+                               }
+                       }
+
                        return match;
                }
 
+               void Error_AmbiguousReference (string name, FullNamedExpression a, FullNamedExpression b, Location loc)
+               {
+                       var report = Compiler.Report;
+                       report.SymbolRelatedToPreviousError (a.Type);
+                       report.SymbolRelatedToPreviousError (b.Type);
+                       report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
+                               name, a.GetSignatureForError (), b.GetSignatureForError ());
+               }
+
                public static Expression LookupStaticUsings (IMemberContext mc, string name, int arity, Location loc)
                {
                        for (var m = mc.CurrentMemberDefinition; m != null; m = m.Parent) {
@@ -1168,26 +1199,27 @@ namespace Mono.CSharp {
                                if (nc.types_using_table != null) {
                                        foreach (var using_type in nc.types_using_table) {
                                                var members = MemberCache.FindMembers (using_type, name, true);
-                                               if (members != null) {
-                                                       foreach (var member in members) {
-                                                               if ((member.Kind & MemberKind.NestedMask) != 0) {
-                                                                       // non-static nested type is included with using static
-                                                               } else {
-                                                                       if ((member.Modifiers & Modifiers.STATIC) == 0)
-                                                                               continue;
-
-                                                                       if ((member.Modifiers & Modifiers.METHOD_EXTENSION) != 0)
-                                                                               continue;
-                                                               }
-
-                                                               if (arity > 0 && member.Arity != arity)
+                                               if (members == null)
+                                                       continue;
+                                               
+                                               foreach (var member in members) {
+                                                       if ((member.Kind & MemberKind.NestedMask) != 0) {
+                                                               // non-static nested type is included with using static
+                                                       } else {
+                                                               if ((member.Modifiers & Modifiers.STATIC) == 0)
                                                                        continue;
 
-                                                               if (candidates == null)
-                                                                       candidates = new List<MemberSpec> ();
-
-                                                               candidates.Add (member);
+                                                               if ((member.Modifiers & Modifiers.METHOD_EXTENSION) != 0)
+                                                                       continue;
                                                        }
+
+                                                       if (arity > 0 && member.Arity != arity)
+                                                               continue;
+
+                                                       if (candidates == null)
+                                                               candidates = new List<MemberSpec> ();
+
+                                                       candidates.Add (member);
                                                }
                                        }
                                }
@@ -1244,16 +1276,20 @@ namespace Mono.CSharp {
                                                continue;
                                        }
 
-                                       entry.Define (this);
+                                       try {
+                                               entry.Define (this);
+                                       } finally {
+                                               //
+                                               // It's needed for repl only, when using clause cannot be resolved don't hold it in
+                                               // global list which is resolved for every evaluation
+                                               //
+                                               if (entry.ResolvedExpression == null) {
+                                                       clauses.RemoveAt (i--);
+                                               }
+                                       }
 
-                                       //
-                                       // It's needed for repl only, when using clause cannot be resolved don't hold it in
-                                       // global list which is resolved for each evaluation
-                                       //
-                                       if (entry.ResolvedExpression == null) {
-                                               clauses.RemoveAt (i--);
+                                       if (entry.ResolvedExpression == null)
                                                continue;
-                                       }
 
                                        var using_ns = entry.ResolvedExpression as NamespaceExpression;
                                        if (using_ns == null) {
@@ -1291,18 +1327,32 @@ namespace Mono.CSharp {
                                        for (int i = 0; i < clauses.Count; ++i) {
                                                var entry = clauses[i];
                                                if (entry.Alias != null) {
-                                                       entry.Define (this);
-                                                       if (entry.ResolvedExpression != null) {
-                                                               aliases.Add (entry.Alias.Value, (UsingAliasNamespace) entry);
-                                                       }
-
-                                                       clauses.RemoveAt (i--);
+                                                       aliases[entry.Alias.Value] = (UsingAliasNamespace) entry;
                                                }
                                        }
                                }
                        }
                }
 
+               protected override void DoDefineContainer ()
+               {
+                       base.DoDefineContainer ();
+
+                       if (clauses != null) {
+                               for (int i = 0; i < clauses.Count; ++i) {
+                                       var entry = clauses[i];
+
+                                       //
+                                       // Finish definition of using aliases not visited during container
+                                       // definition
+                                       //
+                                       if (entry.Alias != null && entry.ResolvedExpression == null) {
+                                               entry.Define (this);
+                                       }
+                               }
+                       }
+               }
+
                public void EnableRedefinition ()
                {
                        is_defined = false;
@@ -1373,6 +1423,7 @@ namespace Mono.CSharp {
                        if (resolved != null) {
                                var compiler = ctx.Module.Compiler;
                                var type = resolved.Type;
+                               resolved = null;
 
                                compiler.Report.SymbolRelatedToPreviousError (type);
                                compiler.Report.Error (138, Location,
@@ -1615,7 +1666,8 @@ namespace Mono.CSharp {
                        // We achieve that by introducing alias-context which redirect any local
                        // namespace or type resolve calls to parent namespace
                        //
-                       resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx), false);
+                       resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx), false) ??
+                               new TypeExpression (InternalType.ErrorType, NamespaceExpression.Location);
                }
        }
 }