From 135dbb9c6d6add208ac0d0f763319fa37ecd6c11 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Wed, 4 Oct 2017 12:40:13 +0200 Subject: [PATCH] [mcs] Allows shadowing of probing pattern variables --- mcs/errors/cs0136-6.cs | 16 ++++++++++++++++ mcs/mcs/cs-parser.jay | 2 +- mcs/mcs/statement.cs | 6 +++--- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 mcs/errors/cs0136-6.cs diff --git a/mcs/errors/cs0136-6.cs b/mcs/errors/cs0136-6.cs new file mode 100644 index 00000000000..79fa771ff4d --- /dev/null +++ b/mcs/errors/cs0136-6.cs @@ -0,0 +1,16 @@ +// CS0136: A local variable named `s' cannot be declared in this scope because it would give a different meaning to `s', which is already used in a `parent or current' scope to denote something else +// Line: 11 + +using System; + +class X +{ + void Test2 (object o) + { + if (o is ValueType s) { + if (o is long s) { + Console.WriteLine (s); + } + } + } +} \ No newline at end of file diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index 6e20a8b13f0..2868d2fd8f6 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -4614,7 +4614,7 @@ additive_expression var lt = (LocatedToken) $4; var lv = new LocalVariable (current_block, lt.Value, lt.Location); is_expr.Variable = lv; - current_block.AddLocalName (lv); + current_block.AddLocalName (lv.Name, lv, true); } $$ = is_expr; diff --git a/mcs/mcs/statement.cs b/mcs/mcs/statement.cs index 0c02bf0562a..369343a5df7 100644 --- a/mcs/mcs/statement.cs +++ b/mcs/mcs/statement.cs @@ -2878,9 +2878,9 @@ namespace Mono.CSharp { AddLocalName (li.Name, li); } - public void AddLocalName (string name, INamedBlockVariable li) + public virtual void AddLocalName (string name, INamedBlockVariable li, bool canShadowChildrenBlockName = false) { - ParametersBlock.TopBlock.AddLocalName (name, li, false); + ParametersBlock.TopBlock.AddLocalName (name, li, canShadowChildrenBlockName); } public virtual void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason) @@ -4257,7 +4257,7 @@ namespace Mono.CSharp { } } - public void AddLocalName (string name, INamedBlockVariable li, bool ignoreChildrenBlocks) + public override void AddLocalName (string name, INamedBlockVariable li, bool ignoreChildrenBlocks) { if (names == null) names = new Dictionary (); -- 2.25.1