title: Chisel : When-otherwise clause not working in function definition
body: <p>I am trying to develop a simple circuit using Chisel 3 to generate the factorial for a number <strong>n</strong>. Here's my implementation :</p>
  
  <pre><code>class Factorial extends Module{
      val io = IO(new Bundle{
          val input = Input(UInt(8.W))
          val output = Output(UInt(16.W))
      })
  
      def factorial(n: UInt): UInt = { 
          when (n === 0.U) {1.U}
          .otherwise {n*factorial(n-1.U)}
      }
  
      io.out := factorial(io.in)
  }
  
  </code></pre>
  
  <p>However, when I try to run it, I get the following error :</p>
  
  <pre><code>cmd26.sc:9: type mismatch;
  found   : Unit
  required: chisel3.UInt
         .otherwise {n*factorial(n-1.U)}
                    ^Compilation Failed
  </code></pre>
  
  <p>Is there any particular reason for this? How do I solve this issue?</p>
  
  <p>Also, I realize that an easy solution is to just have the number <strong>n</strong> to be of type <code>Int</code>, and have an if-else clause instead. Is there any way to type cast the parameter being passed during function call (i.e. from <code>chisel3.UInt</code> to <code>Int</code>)?</p>