[Mono-bugs] [Bug 29479][Min] Changed - mcs allows 'using XXX' when XXX does not exists

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
27 Aug 2002 11:02:34 -0000

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by lupus@ximian.com.


--- shadow/29479	Mon Aug 26 19:26:42 2002
+++ shadow/29479.tmp.666	Tue Aug 27 07:02:34 2002
@@ -1,14 +1,14 @@
 Bug#: 29479
 Product: Mono/MCS
 Version: unspecified
+OS: unknown
 OS Details: 
 Status: NEW   
+Severity: Unknown
 Priority: Minor
 Component: Misc
 AssignedTo: mono-bugs@ximian.com                            
 ReportedBy: gonzalo@ximian.com               
 QAContact: mono-bugs@ximian.com
 TargetMilestone: ---
@@ -33,6 +33,65 @@
 Compilation succeeded.
 Expected Results:
 bugnuevo.cs(1,7): error CS0246: The type or namespace name
 'NonExistentNamespace' could not be found (are you
         missing a using directive or an assembly reference?)
+------- Additional Comments From lupus@ximian.com  2002-08-27 07:02 -------
+Lets see if this time miguel will leave the bug open providing some
+data (see bugs# 24510 and 24516)... :-)
+Doing this check the simple way will increase startup time by 0.8
+seconds (on a PIII 1.1 cpu): see the program below.
+using System;
+using System.Reflection;
+using System.Collections;
+class T {
+	static void Main () {
+		Hashtable hash = new Hashtable ();
+		int count = 0;
+		string[] assemblies = new string[] {
+			"mscorlib", "System", "System.Xml",
+			"System.Data", "System.Web"
+		};
+		foreach (string s in assemblies) {
+			Assembly a = Assembly.LoadWithPartialName (s);
+			if (a == null) {
+				Console.WriteLine ("Cannot load {0}", s);
+				continue;
+			}
+			Type[] types = a.GetTypes ();
+			foreach (Type t in types) {
+				string ns = t.Namespace;
+				if (!hash.Contains (ns)) {
+					hash.Add (t.Namespace, t);
+				}
+				count++;
+			}
+		}
+		Console.WriteLine ("Total types: {0}", count);
+		Console.WriteLine ("Total namespaces: {0}", hash.Count);
+	}
+However, there is a trick we can easily do that will make only
+programs with a wrong using directive pay the time to do the above check.
+At parse time we keep a hash of the namespaces requested in using
+directives (and in what file they were, to report errors).
+When resolving the tree and using GetType() on the loaded assemblies,
+we mark the namespace from that type as seen.
+At the end of the compilation we check what namespaces were not marked
+as seen and we'll have to run the code above to check if the namespace
+exists at all. In almost all the programs this check won't need to be
+done because it happens only when there was a real error or the using
+directive was not needed and no type considered by the compiler
+happened to be in that namespace (in this latter case we may also want
+to emit a warning, like: useless using directive).
+As an alternative implementation, we could add a call to Assembly
+(that is Invoke()d by mcs) that returns an array of namespaces defined
+in the assembly: this will be very fast in the mono runtime (but it
+will slow-down mcs running on the ms runtime, since that will have to
+use the above code). We can submit this idea to the MS Reflection guys
+as well.