In general you can only use code that generates chisel hardware constructs within a Module (literals are an exception). So the typical methodology would be to write a wrapper and see that the generated code contains what you expect. For example here's a little test of your function
"test non-module generator" in {
// pads out rectangular vec into square nested seq, fills with values based on indices
class Wrapper extends Module {
val square = (Util.getSquare(Vec(4, Vec(2,Bool()))))
square.indices.foreach { i => square(i).indices.foreach { j => square(i)(j) := ((i + j ) % 2 == 0).B}}
val out = IO(Output(Vec(4, Vec(4,Bool()))))
out.indices.foreach { i => out(i).indices.foreach { j => out(i)(j) := square(i)(j)}}
}
val firrtlSource = ChiselStage.emitFirrtl(new Wrapper)
println(firrtlSource)
firrtlSource should contain ("wire square_4_4")
}
You can also test your wrapper function with the chiseltest basic test harness, for example:
test(new Wrapper) { dut =>
dut.out(3)(3).expect(true.B)
}