[mcs] Allows shadowing of probing pattern variables
authorMarek Safar <marek.safar@gmail.com>
Wed, 4 Oct 2017 10:40:13 +0000 (12:40 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 4 Oct 2017 12:49:36 +0000 (14:49 +0200)
mcs/errors/cs0136-6.cs [new file with mode: 0644]
mcs/mcs/cs-parser.jay
mcs/mcs/statement.cs

diff --git a/mcs/errors/cs0136-6.cs b/mcs/errors/cs0136-6.cs
new file mode 100644 (file)
index 0000000..79fa771
--- /dev/null
@@ -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
index 6e20a8b13f0aeedac01b0a29afcb61722a4b34c1..2868d2fd8f692fd3d9362e9431b5719dc4301148 100644 (file)
@@ -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;
index 0c02bf0562a271da6811188fd102ecf836f0986a..369343a5df7703515bec4e4f8963e4f71772467e 100644 (file)
@@ -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<string, object> ();