* ecore.cs, cs-parser.jay, statement.cs: Error reporting fixes.
svn path=/trunk/mcs/; revision=108213
+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
// 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;
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)
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;
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.
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;
}
//