Searching for an attributes in probing mode should not report errors for other attrib...
authorMarek Safar <marek.safar@gmail.com>
Thu, 16 Aug 2012 10:49:13 +0000 (12:49 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 16 Aug 2012 10:49:13 +0000 (12:49 +0200)
mcs/errors/cs0246-9.cs [new file with mode: 0644]
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/ecore.cs
mcs/mcs/parameter.cs

diff --git a/mcs/errors/cs0246-9.cs b/mcs/errors/cs0246-9.cs
new file mode 100644 (file)
index 0000000..b28fd11
--- /dev/null
@@ -0,0 +1,18 @@
+// CS0246: The type or namespace name `DllImport' could not be found. Are you missing an assembly reference?
+// Line: 16
+
+using System;
+using System.Threading;
+
+public class Test
+{
+       static void Main ()
+       {
+               var tr = new Thread (delegate () {
+                       Foo ();
+               });
+       }
+
+       [DllImport ("Foo")]
+       extern static void Foo ();
+} 
index 46c0116bd18b3e60c6d89ebb463a946e99528a41..4fbc993a55a882591eb2192cfbe79fa163027afe 100644 (file)
@@ -144,6 +144,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool ResolveError {
+                       get {
+                               return resolve_error;
+                       }
+               }
+
                public ATypeNameExpression TypeExpression {
                        get {
                                return expression;
@@ -276,7 +282,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
                /// </summary>
-               void ResolveAttributeType ()
+               void ResolveAttributeType (bool comparisonOnly)
                {
                        SessionReportPrinter resolve_printer = new SessionReportPrinter ();
                        ReportPrinter prev_recorder = Report.SetPrinter (resolve_printer);
@@ -311,9 +317,12 @@ namespace Mono.CSharp {
                        }
 
                        if (t1_is_attr && t2_is_attr && t1 != t2) {
-                               Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'",
-                                       GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ());
-                               resolve_error = true;
+                               if (!comparisonOnly) {
+                                       Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'",
+                                               GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ());
+                                       resolve_error = true;
+                               }
+
                                return;
                        }
 
@@ -327,6 +336,9 @@ namespace Mono.CSharp {
                                return;
                        }
 
+                       if (comparisonOnly)
+                               return;
+
                        resolve_error = true;
 
                        if (t1 != null) {
@@ -346,10 +358,10 @@ namespace Mono.CSharp {
                        resolve_printer.Merge (prev_recorder);
                }
 
-               public TypeSpec ResolveType ()
+               public TypeSpec ResolveTypeForComparison ()
                {
                        if (Type == null && !resolve_error)
-                               ResolveAttributeType ();
+                               ResolveAttributeType (true);
                        return Type;
                }
 
@@ -425,7 +437,7 @@ namespace Mono.CSharp {
                        arg_resolved = true;
 
                        if (Type == null) {
-                               ResolveAttributeType ();
+                               ResolveAttributeType (false);
                                if (Type == null)
                                        return null;
                        }
@@ -1193,6 +1205,16 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool HasResolveError()
+               {
+                       foreach (var a in Attrs) {
+                               if (a.ResolveError)
+                                       return true;
+                       }
+
+                       return false;
+               }
+
                public Attribute Search (PredefinedAttribute t)
                {
                        return Search (null, t);
@@ -1204,7 +1226,7 @@ namespace Mono.CSharp {
                                if (explicitTarget != null && a.ExplicitTarget != explicitTarget)
                                        continue;
 
-                               if (a.ResolveType () == t)
+                               if (a.ResolveTypeForComparison () == t)
                                        return a;
                        }
                        return null;
@@ -1218,7 +1240,7 @@ namespace Mono.CSharp {
                        List<Attribute> ar = null;
 
                        foreach (Attribute a in Attrs) {
-                               if (a.ResolveType () == t) {
+                               if (a.ResolveTypeForComparison () == t) {
                                        if (ar == null)
                                                ar = new List<Attribute> (Attrs.Count);
                                        ar.Add (a);
index faa84758853b87df9f6195708bbe0afd600e8e54..ffc0c44738e957775eebf9bc43618eb6fe7060a2 100644 (file)
@@ -3321,7 +3321,7 @@ namespace Mono.CSharp
                {
                        // for extern static method must be specified either DllImport attribute or MethodImplAttribute.
                        // We are more strict than csc and report this as an error because SRE does not allow emit that
-                       if ((ModFlags & Modifiers.EXTERN) != 0 && !is_external_implementation) {
+                       if ((ModFlags & Modifiers.EXTERN) != 0 && !is_external_implementation && (OptAttributes == null || !OptAttributes.HasResolveError ())) {
                                if (this is Constructor) {
                                        Report.Warning (824, 1, Location,
                                                "Constructor `{0}' is marked `external' but has no external implementation specified", GetSignatureForError ());
index 2f1405575dbcff386ca984c4a63e3045259d49d9..fb502e6146fb29057fbd530603a3e54b9bbc7e0f 100644 (file)
@@ -4848,13 +4848,18 @@ namespace Mono.CSharp {
                                return null;
 
                        //
-                       // Check ObsoleteAttribute on the best method
+                       // Don't run possibly expensive checks in probing mode
                        //
-                       ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
-                       if (oa != null && !rc.IsObsolete)
-                               AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
+                       if (!rc.IsInProbingMode) {
+                               //
+                               // Check ObsoleteAttribute on the best method
+                               //
+                               ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
+                               if (oa != null && !rc.IsObsolete)
+                                       AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
 
-                       best_candidate.MemberDefinition.SetIsUsed ();
+                               best_candidate.MemberDefinition.SetIsUsed ();
+                       }
 
                        args = best_candidate_args;
                        return (T) best_candidate;
index 365f876f0aa4f318f21cd34f114b7a1703dd8d66..982785ff3c3fa799600b6e95b199466528b24201 100644 (file)
@@ -418,7 +418,7 @@ namespace Mono.CSharp {
                        TypeSpec caller_type;
 
                        foreach (var attr in attributes.Attrs) {
-                               var atype = attr.ResolveType ();
+                               var atype = attr.ResolveTypeForComparison ();
                                if (atype == null)
                                        continue;