summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/chiselTests/When.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/When.scala b/src/test/scala/chiselTests/When.scala
index a1a7afb7..58d5a1bd 100644
--- a/src/test/scala/chiselTests/When.scala
+++ b/src/test/scala/chiselTests/When.scala
@@ -106,4 +106,26 @@ class WhenSpec extends ChiselFlatSpec {
"Conditional connections to submodule ports" should "be handled properly" in {
assertTesterPasses(new SubmoduleWhenTester)
}
+
+ "Returning in a when scope" should "give a reasonable error message" in {
+ val e = the [ChiselException] thrownBy {
+ elaborate(new Module {
+ val io = IO(new Bundle {
+ val foo = Input(UInt(8.W))
+ val bar = Input(UInt(8.W))
+ val cond = Input(Bool())
+ val out = Output(UInt(8.W))
+ })
+ def func(): UInt = {
+ when(io.cond) {
+ // This is bad, do not do this!!!
+ return io.foo
+ }
+ return io.bar
+ }
+ io.out := func()
+ })
+ }
+ e.getMessage should include ("Cannot exit from a when() block with a \"return\"")
+ }
}