Author: marek
Date: 2007-10-11 05:25:22 -0400 (Thu, 11 Oct 2007)
New Revision: 87323
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/anonymous.cs
trunk/mcs/mcs/ecore.cs
trunk/mcs/mcs/expression.cs
trunk/mcs/mcs/lambda.cs
trunk/mcs/mcs/location.cs
trunk/mcs/mcs/report.cs
trunk/mcs/mcs/statement.cs
Log:
2007-10-11 Marek Safar <[EMAIL PROTECTED]>
* report.cs: Implemented message recorder. It is used mainly for lambda
expressions to capture otherwise swallowed error messages.
* anonymous.cs, lambda.cs.cs: Do full parameters check.
* ecore.cs (ExtensionMethodGroup): Report binding failure at the botton
and not at the top.
(MethodGroupExpr.DoResolve): Use message recorder for error handling.
* expression.cs (MemberAccess): Always report lookup failure.
* location.cs: Implemented Equals, GetHashCode.
* statement.cs (Return.DoResolve): Fixed hardcoded error argument.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/ChangeLog 2007-10-11 09:25:22 UTC (rev 87323)
@@ -1,3 +1,20 @@
+2007-10-11 Marek Safar <[EMAIL PROTECTED]>
+
+ * report.cs: Implemented message recorder. It is used mainly for lambda
+ expressions to capture otherwise swallowed error messages.
+
+ * anonymous.cs, lambda.cs.cs: Do full parameters check.
+
+ * ecore.cs (ExtensionMethodGroup): Report binding failure at the botton
+ and not at the top.
+ (MethodGroupExpr.DoResolve): Use message recorder for error handling.
+
+ * expression.cs (MemberAccess): Always report lookup failure.
+
+ * location.cs: Implemented Equals, GetHashCode.
+
+ * statement.cs (Return.DoResolve): Fixed hardcoded error argument.
+
2007-10-10 Jb Evain <[EMAIL PROTECTED]>
* codegen.cs: re-enable assembly version check.
Modified: trunk/mcs/mcs/anonymous.cs
===================================================================
--- trunk/mcs/mcs/anonymous.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/anonymous.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -1196,17 +1196,19 @@
return false;
}
- bool VerifyParameterCompatibility (Type delegate_type,
ParameterData invoke_pd, bool ignoreErrors)
+ protected bool VerifyParameterCompatibility (Type
delegate_type, ParameterData invoke_pd, bool ignoreErrors)
{
if (Parameters.Count != invoke_pd.Count) {
if (ignoreErrors)
return false;
- Report.SymbolRelatedToPreviousError
(delegate_type);
Report.Error (1593, loc, "Delegate `{0}' does
not take `{1}' arguments",
TypeManager.CSharpName
(delegate_type), Parameters.Count.ToString ());
return false;
}
+
+ if (!HasExplicitParameters)
+ return true;
bool error = false;
for (int i = 0; i < Parameters.Count; ++i) {
Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/ecore.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -335,6 +335,10 @@
public virtual void Error_ValueCannotBeConverted (EmitContext
ec, Location loc, Type target, bool expl)
{
+ // The error was already reported as CS1660
+ if (type == TypeManager.anonymous_method_type)
+ return;
+
if (Type.FullName == target.FullName){
Report.ExtraInformation (loc,
String.Format (
@@ -3054,14 +3058,7 @@
((ExtensionMethodGroupExpr)mg).extension_argument = (Argument)arguments [0];
arguments.RemoveAt (0);
- if (mg != null)
- return mg;
-
- if (!may_fail)
- // TODO: This should be some meaningful error
message
- Invocation.Error_WrongNumArguments (loc, Name,
arguments.Count);
-
- return null;
+ return mg;
}
MethodGroupExpr ResolveOverloadExtensions (EmitContext ec,
ArrayList arguments, NamespaceEntry ns, Location loc)
@@ -3077,7 +3074,7 @@
// Search continues
ExtensionMethodGroupExpr e = ns.LookupExtensionMethod
(type, null, Name);
if (e == null)
- return null;
+ return base.OverloadResolve (ec, arguments,
false, loc);
e.ExtensionExpression = ExtensionExpression;
return e.ResolveOverloadExtensions (ec, arguments,
e.namespaceEntry, loc);
@@ -3917,9 +3914,13 @@
nmethods = j;
}
- int applicable_errors = Report.Errors;
-
//
+ // Enable message recording, it's used mainly by lambda
expressions
+ //
+ Report.IMessageRecorder msg_recorder = new
Report.MessageRecorder ();
+ Report.IMessageRecorder prev_recorder =
Report.SetMessageRecorder (msg_recorder);
+
+ //
// First we construct the set of applicable methods
//
bool is_sorted = true;
@@ -3948,9 +3949,14 @@
is_applicable = true;
}
- if (!is_applicable)
+ if (!is_applicable) {
+ if (msg_recorder != null)
+ msg_recorder.EndSession ();
continue;
+ }
+ msg_recorder = null;
+
candidates.Add (Methods [i]);
if (applicable_type == null)
@@ -3962,7 +3968,8 @@
}
}
- if (applicable_errors != Report.Errors)
+ Report.SetMessageRecorder (prev_recorder);
+ if (msg_recorder != null && msg_recorder.PrintMessages
())
return null;
int candidate_top = candidates.Count;
@@ -4271,6 +4278,7 @@
int j;
int a_idx = 0;
Argument a = null;
+ int errors = Report.Errors;
for (j = 0; j < param_count; j++) {
Type parameter_type = pd.ParameterType (j);
Parameter.Modifier pm = pd.ParameterModifier
(j);
@@ -4325,7 +4333,7 @@
if (a_idx == arg_count)
return true;
- if (!may_fail)
+ if (!may_fail && Report.Errors == errors)
Error_InvalidArguments (ec, loc, a_idx, method,
delegate_type, a, pd);
return false;
}
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/expression.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -6610,10 +6610,10 @@
return ex_method_lookup.DoResolve (ec);
}
- if (!ec.IsInProbingMode)
- Error_MemberLookupFailed (
- ec.ContainerType, expr_type,
expr_type, Identifier, null,
- AllMemberTypes,
AllBindingFlags);
+ expr = expr_resolved;
+ Error_MemberLookupFailed (
+ ec.ContainerType, expr_type, expr_type,
Identifier, null,
+ AllMemberTypes, AllBindingFlags);
return null;
}
@@ -8745,14 +8745,19 @@
type = e.Type;
if (type == TypeManager.void_type || type ==
TypeManager.null_type ||
type == TypeManager.anonymous_method_type ||
type.IsPointer) {
- Report.Error (828, loc, "An anonymous type
property `{0}' cannot be initialized with `{1}'",
- Name, e.GetSignatureForError ());
+ Error_InvalidInitializer (e);
return null;
}
return e;
}
+ protected virtual void Error_InvalidInitializer (Expression
initializer)
+ {
+ Report.Error (828, loc, "An anonymous type property
`{0}' cannot be initialized with `{1}'",
+ Name, initializer.GetSignatureForError ());
+ }
+
public override void Emit (EmitContext ec)
{
throw new InternalErrorException ("Should not be
reached");
Modified: trunk/mcs/mcs/lambda.cs
===================================================================
--- trunk/mcs/mcs/lambda.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/lambda.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -58,7 +58,7 @@
// If L has an implicitly typed parameter list we make
implicit parameters explicit
// Set each parameter of L is given the type of the
corresponding parameter in D
//
- if (Parameters.Count != d_params.Count)
+ if (!VerifyParameterCompatibility (delegateType,
d_params, ec.IsInProbingMode))
return null;
if (Parameters.Types == null)
Modified: trunk/mcs/mcs/location.cs
===================================================================
--- trunk/mcs/mcs/location.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/location.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -243,6 +243,19 @@
}
checkpoints [checkpoint_index] = new Checkpoint (file,
row);
}
+
+ public override bool Equals (object o)
+ {
+ if (o is Location)
+ return ((Location)o).CheckpointIndex ==
CheckpointIndex;
+
+ return false;
+ }
+
+ public override int GetHashCode ()
+ {
+ return token.GetHashCode ();
+ }
public override string ToString ()
{
Modified: trunk/mcs/mcs/report.cs
===================================================================
--- trunk/mcs/mcs/report.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/report.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -73,6 +73,7 @@
// A stack because of `Report.Errors == errors;'
//
static Stack error_stack;
+ static Stack warning_stack;
static bool reporting_disabled;
static int warning_level;
@@ -80,7 +81,7 @@
/// <summary>
/// List of symbols related to reported error/warning. You have
to fill it before error/warning is reported.
/// </summary>
- static StringCollection extra_information = new
StringCollection ();
+ static ArrayList extra_information = new ArrayList ();
//
// IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
@@ -124,19 +125,167 @@
if (error_stack == null)
error_stack = new Stack ();
error_stack.Push (Errors);
+
+ if (Warnings > 0) {
+ if (warning_stack == null)
+ warning_stack = new Stack ();
+ warning_stack.Push (Warnings);
+ }
+
reporting_disabled = true;
}
public static void EnableReporting ()
{
+ if (warning_stack != null)
+ Warnings = (int) warning_stack.Pop ();
+
Errors = (int) error_stack.Pop ();
if (error_stack.Count == 0) {
reporting_disabled = false;
}
}
+
+ public static IMessageRecorder msg_recorder;
+
+ public static IMessageRecorder SetMessageRecorder
(IMessageRecorder recorder)
+ {
+ IMessageRecorder previous = msg_recorder;
+ msg_recorder = recorder;
+ return previous;
+ }
+
+ public interface IMessageRecorder
+ {
+ void EndSession ();
+ void AddMessage (AbstractMessage msg);
+ bool PrintMessages ();
+ }
+
+ //
+ // Default message recorder, it uses two types of message
groups.
+ // Common messages: messages reported in all sessions.
+ // Merged messages: union of all messages in all sessions.
+ //
+ public struct MessageRecorder : IMessageRecorder
+ {
+ ArrayList session_messages;
+ //
+ // A collection of exactly same messages reported in
all sessions
+ //
+ ArrayList common_messages;
+
+ //
+ // A collection of unique messages reported in all
sessions
+ //
+ ArrayList merged_messages;
+
+ public void EndSession ()
+ {
+ if (session_messages == null)
+ return;
+
+ //
+ // Handles the first session
+ //
+ if (common_messages == null) {
+ common_messages = new ArrayList
(session_messages);
+ merged_messages = session_messages;
+ session_messages = null;
+ return;
+ }
+
+ //
+ // Store common messages if any
+ //
+ for (int i = 0; i < common_messages.Count; ++i)
{
+ AbstractMessage cmsg =
(AbstractMessage) common_messages [i];
+ bool common_msg_found = false;
+ foreach (AbstractMessage msg in
session_messages) {
+ if (cmsg.Equals (msg)) {
+ common_msg_found = true;
+ break;
+ }
+ }
+
+ if (!common_msg_found)
+ common_messages.RemoveAt (i);
+ }
+
+ //
+ // Merge session and previous messages
+ //
+ for (int i = 0; i < session_messages.Count;
++i) {
+ AbstractMessage msg = (AbstractMessage)
session_messages [i];
+ bool msg_found = false;
+ for (int ii = 0; ii <
merged_messages.Count; ++ii) {
+ if (msg.Equals (merged_messages
[ii])) {
+ msg_found = true;
+ break;
+ }
+ }
+
+ if (!msg_found)
+ merged_messages.Add (msg);
+ }
+ }
+
+ public void AddMessage (AbstractMessage msg)
+ {
+ if (session_messages == null)
+ session_messages = new ArrayList ();
+
+ session_messages.Add (msg);
+ }
+
+ //
+ // Prints collected messages, common messages have a
priority
+ //
+ public bool PrintMessages ()
+ {
+ ArrayList messages_to_print = merged_messages;
+ if (common_messages != null &&
common_messages.Count > 0) {
+ messages_to_print = common_messages;
+ }
+
+ if (messages_to_print == null)
+ return false;
+
+ foreach (AbstractMessage msg in
messages_to_print)
+ msg.Print ();
+
+ return true;
+ }
+ }
- abstract class AbstractMessage {
+ public abstract class AbstractMessage
+ {
+ readonly string[] extra_info;
+ protected readonly int code;
+ protected readonly Location location;
+ readonly string message;
+ protected AbstractMessage (int code, Location loc,
string msg, ArrayList extraInfo)
+ {
+ this.code = code;
+ if (code < 0)
+ this.code = 8000 - code;
+
+ this.location = loc;
+ this.message = msg;
+ if (extraInfo.Count != 0) {
+ this.extra_info =
(string[])extraInfo.ToArray (typeof (string));
+ }
+ }
+
+ protected AbstractMessage (AbstractMessage aMsg)
+ {
+ this.code = aMsg.code;
+ this.location = aMsg.location;
+ this.message = aMsg.message;
+ this.extra_info = aMsg.extra_info;
+ }
+
static void Check (int code)
{
if (code == expected_error) {
@@ -144,53 +293,69 @@
}
}
+ public override bool Equals (object obj)
+ {
+ AbstractMessage msg = obj as AbstractMessage;
+ if (msg == null)
+ return false;
+
+ return code == msg.code && location.Equals
(msg.location) && message == msg.message;
+ }
+
+ public override int GetHashCode ()
+ {
+ return code.GetHashCode ();
+ }
+
public abstract bool IsWarning { get; }
public abstract string MessageType { get; }
- public virtual void Print (int code, Location location,
string text)
+ public virtual void Print ()
{
- if (reporting_disabled) {
+ if (msg_recorder != null) {
//
- // This line is useful when debugging
the inner working of
- // Lambdas when various compilation
attempts are done.
+ // This line is useful when debugging
messages recorder
//
- //Console.WriteLine ("DISABLED: {0} {1}
{2}", code, location, text);
+ // Console.WriteLine ("RECORDING: {0}
{1} {2}", code, location, message);
+ msg_recorder.AddMessage (this);
return;
}
-
- if (code < 0)
- code = 8000-code;
+ if (reporting_disabled)
+ return;
+
StringBuilder msg = new StringBuilder ();
if (!location.IsNull) {
msg.Append (location.ToString ());
- msg.Append (' ');
+ msg.Append (" ");
}
- msg.AppendFormat ("{0} CS{1:0000}: {2}",
MessageType, code, text);
+ msg.AppendFormat ("{0} CS{1:0000}: {2}",
MessageType, code, message);
Stderr.WriteLine (msg.ToString ());
- foreach (string s in extra_information)
- Stderr.WriteLine (s + MessageType +
")");
+ if (extra_info != null) {
+ foreach (string s in extra_info)
+ Stderr.WriteLine (s +
MessageType + ")");
+ }
- extra_information.Clear ();
-
if (Stacktrace)
Console.WriteLine (FriendlyStackTrace
(new StackTrace (true)));
if (Fatal) {
if (!IsWarning || WarningsAreErrors)
- throw new Exception (text);
+ throw new Exception (message);
}
Check (code);
}
}
- sealed class WarningMessage : AbstractMessage {
+ sealed class WarningMessage : AbstractMessage
+ {
readonly int Level;
- public WarningMessage (int level)
+ public WarningMessage (int code, int level, Location
loc, string message, ArrayList extra_info)
+ : base (code, loc, message, extra_info)
{
Level = level;
}
@@ -199,7 +364,7 @@
get { return true; }
}
- bool IsEnabled (int code, Location loc)
+ bool IsEnabled ()
{
if (WarningLevel < Level)
return false;
@@ -210,30 +375,28 @@
}
}
- if (warning_regions_table == null || loc.IsNull)
+ if (warning_regions_table == null ||
location.IsNull)
return true;
- WarningRegions regions =
(WarningRegions)warning_regions_table [loc.Name];
+ WarningRegions regions =
(WarningRegions)warning_regions_table [location.Name];
if (regions == null)
return true;
- return regions.IsWarningEnabled (code, loc.Row);
+ return regions.IsWarningEnabled (code,
location.Row);
}
- public override void Print (int code, Location
location, string text)
+ public override void Print ()
{
- if (!IsEnabled (code, location)) {
- extra_information.Clear ();
+ if (!IsEnabled ())
return;
- }
if (WarningsAreErrors) {
- new ErrorMessage ().Print (code,
location, text);
+ new ErrorMessage (this).Print ();
return;
}
Warnings++;
- base.Print (code, location, text);
+ base.Print ();
}
public override string MessageType {
@@ -243,12 +406,22 @@
}
}
- sealed class ErrorMessage : AbstractMessage {
+ sealed class ErrorMessage : AbstractMessage
+ {
+ public ErrorMessage (int code, Location loc, string
message, ArrayList extraInfo)
+ : base (code, loc, message, extraInfo)
+ {
+ }
- public override void Print(int code, Location location,
string text)
+ public ErrorMessage (AbstractMessage aMsg)
+ : base (aMsg)
{
+ }
+
+ public override void Print()
+ {
Errors++;
- base.Print (code, location, text);
+ base.Print ();
}
public override bool IsWarning {
@@ -260,7 +433,6 @@
return "error";
}
}
-
}
public static void FeatureIsNotISO1 (Location loc, string
feature)
@@ -403,9 +575,6 @@
public static void ExtraInformation (Location loc, string msg)
{
- if (reporting_disabled)
- return;
-
extra_information.Add (String.Format ("{0} {1}", loc,
msg));
}
@@ -424,26 +593,30 @@
static public void Warning (int code, int level, Location loc,
string message)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, message);
+ WarningMessage w = new WarningMessage (code, level,
loc, message, extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
static public void Warning (int code, int level, Location loc,
string format, string arg)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, String.Format (format, arg));
+ WarningMessage w = new WarningMessage (code, level,
loc, String.Format (format, arg), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
static public void Warning (int code, int level, Location loc,
string format, string arg1, string arg2)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, String.Format (format, arg1, arg2));
+ WarningMessage w = new WarningMessage (code, level,
loc, String.Format (format, arg1, arg2), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
static public void Warning (int code, int level, Location loc,
string format, params object[] args)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, String.Format (format, args));
+ WarningMessage w = new WarningMessage (code, level,
loc, String.Format (format, args), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
static public void Warning (int code, int level, string message)
@@ -468,17 +641,20 @@
static public void Error (int code, Location loc, string error)
{
- new ErrorMessage ().Print (code, loc, error);
+ new ErrorMessage (code, loc, error,
extra_information).Print ();
+ extra_information.Clear ();
}
static public void Error (int code, Location loc, string
format, string arg)
{
- new ErrorMessage ().Print (code, loc, String.Format
(format, arg));
+ new ErrorMessage (code, loc, String.Format (format,
arg), extra_information).Print ();
+ extra_information.Clear ();
}
static public void Error (int code, Location loc, string
format, string arg1, string arg2)
{
- new ErrorMessage ().Print (code, loc, String.Format
(format, arg1, arg2));
+ new ErrorMessage (code, loc, String.Format (format,
arg1, arg2), extra_information).Print ();
+ extra_information.Clear ();
}
static public void Error (int code, Location loc, string
format, params object[] args)
@@ -525,9 +701,6 @@
public static int WarningLevel {
get {
- if (reporting_disabled)
- return 0;
-
return warning_level;
}
set {
Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs 2007-10-11 08:28:13 UTC (rev 87322)
+++ trunk/mcs/mcs/statement.cs 2007-10-11 09:25:22 UTC (rev 87323)
@@ -761,7 +761,7 @@
if (Expr == null) {
if (am != null) {
Report.Error (1662, loc,
- "Cannot convert
`{0}' to delegate type `D' because some of the return types in the block are
not implicitly convertible to the delegate return type",
+ "Cannot convert
`{0}' to delegate type `{1}' because some of the return types in the block are
not implicitly convertible to the delegate return type",
am.ContainerType, am.GetSignatureForError ());
}
return false;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches