title: PowerShell: passing blocks as parameters to functions
body: <p>I will explain my question on an example. Let's have following code in C#:</p>
  
  <pre><code>void A(Action block)
  {
   B(() =&gt;
   {
    Console.WriteLine(2);
    block();
   });
  }
  
  void B(Action block)
  {
   Console.WriteLine(1);
   block();
  }
  
  void Main()
  {
   A(() =&gt;
   {
    Console.WriteLine(3);
   });
  }
  </code></pre>
  
  <p>The output of this code is:</p>
  
  <pre><code>1
  2
  3
  </code></pre>
  
  <p>Now, I want to write this code in PowerShell:</p>
  
  <pre><code>function A($block) {
      B {
          2
          . $block
      }
  }
  
  function B($block) {
      1
      . $block
  }
  
  A {
      3
  }
  </code></pre>
  
  <p>However, this code causes a call depth overflow:</p>
  
  <blockquote>
    <p>The script failed due to call depth
    overflow.  The call depth reached 1001
    and the maximum is 1000.</p>
  </blockquote>
  
  <p>I found that if I change the name of the parameter of the function B, it will work.</p>
  
  <p>Is it a feature or a bug (or both)? How can I make that work in PowerShell without having parameters unique across functions?</p>