2008-07-17 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Fri, 18 Jul 2008 09:47:11 +0000 (09:47 -0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 18 Jul 2008 09:47:11 +0000 (09:47 -0000)
* ecore.cs, cs-parser.jay, statement.cs: Error reporting fixes.

svn path=/trunk/mcs/; revision=108213

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay
mcs/mcs/ecore.cs
mcs/mcs/statement.cs

index 4371b77b8578c11271627cd7f24b2a86f6e81006..e0f5e58164b4be226e5a5e82c9c3463a9574b98e 100644 (file)
@@ -1,3 +1,7 @@
+2008-07-17  Marek Safar  <marek.safar@gmail.com>
+
+       * ecore.cs, cs-parser.jay, statement.cs: Error reporting fixes.
+
 2008-07-17  Marek Safar  <marek.safar@gmail.com>
 
        A fix for bug #367536
index ac4633b6c7c2c823f3c2b90d01e9557bf6b5f503..bc892c146b0da46aa6f918c0279cec41ddb56736 100644 (file)
@@ -5748,7 +5748,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
        // int j = 1;  int k = j + 1;
        //
        if (current_block.Used)
-               implicit_block = new Block (current_block, loc, Location.Null);
+               implicit_block = new Block (current_block, loc, lexer.Location);
        else
                implicit_block = current_block;
 
index ecf5ab8fe64d161b044720ddd332619b7790d9c7..53a174cbbab12abc3f689323ed5aa93af7ded81c 100644 (file)
@@ -393,10 +393,9 @@ namespace Mono.CSharp {
                                TypeManager.CSharpName (target));
                }
 
-               protected void Error_VariableIsUsedBeforeItIsDeclared (string name)
+               public virtual void Error_VariableIsUsedBeforeItIsDeclared (string name)
                {
-                       Report.Error (841, loc, "The variable `{0}' cannot be used before it is declared",
-                               name);
+                       Report.Error (841, loc, "A local variable `{0}' cannot be used before it is declared", name);
                }
 
                protected virtual void Error_TypeDoesNotContainDefinition (Type type, string name)
@@ -5039,6 +5038,13 @@ namespace Mono.CSharp {
                                base.EmitSideEffect (ec);
                }
 
+               public override void Error_VariableIsUsedBeforeItIsDeclared (string name)
+               {
+                       Report.Error (844, loc,
+                               "A local variable `{0}' cannot be used before it is declared. Consider renaming the local variable when it hides the field `{1}'",
+                               name, GetSignatureForError ());
+               }
+
                public void AddressOf (EmitContext ec, AddressOp mode)
                {
                        ILGenerator ig = ec.ig;
index 5db9def589dd9ad30ab1d9af6e8b2785848e385e..156442fec7c5a9d8f82e8dc26682208c69cb333c 100644 (file)
@@ -1796,6 +1796,12 @@ namespace Mono.CSharp {
                        if (e is VariableReference || (e is Constant && b.GetLocalInfo (name) != null))
                                return true;
 
+                       if (this is ToplevelBlock) {
+                               Report.SymbolRelatedToPreviousError (kvi.Location, name);
+                               e.Error_VariableIsUsedBeforeItIsDeclared (name);
+                               return false;
+                       }
+
                        //
                        // Even though we detected the error when the name is used, we
                        // treat it as if the variable declaration was in error.
@@ -2214,13 +2220,14 @@ namespace Mono.CSharp {
                                        if (s is EmptyStatement)
                                                continue;
 
-                                       if (s is Block)
-                                               ((Block) s).unreachable = true;
-
                                        if (!unreachable_shown && !(s is LabeledStatement)) {
                                                Report.Warning (162, 2, s.loc, "Unreachable code detected");
                                                unreachable_shown = true;
                                        }
+
+                                       Block c_block = s as Block;
+                                       if (c_block != null)
+                                               c_block.unreachable = c_block.unreachable_shown = true;
                                }
 
                                //