chipsalliance / chipsalliance/chisel

DataView of an Empty Module throws java.lang.IndexOutOfBoundsException

Open
#3,203 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

Description

The following errors as it tries to get the `lastId` for an empty module (which allocated no ids?). I would expect to get a "view is non-total" error:

```scala
//> using scala "2.13.10"
//> using repository "https://s01.oss.sonatype.org/content/repositories/snapshots"
//> using lib "org.chipsalliance::chisel::5.0.0-M2"
//> using plugin "org.chipsalliance:::chisel-plugin::5.0.0-M2"
//> using options "-Ymacro-annotations"

import chisel3._
import chisel3.experimental.dataview._
import circt.stage.ChiselStage

class Bar extends RawModule

class Baz extends Bundle {
val a = Bool()
}

class Foo extends Module {

private val bar = Module(new Bar)
private val baz = Wire(new Baz)

private implicit val view = PartialDataView[Bar, Baz](
_ => new Baz
)

baz := bar.viewAs[Baz]

}

object Main extends App {
println(
ChiselStage.emitSystemVerilog(
gen = new Foo,
firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info")
)
)
}
```

This produces:

```
Exception in thread "main" java.lang.IndexOutOfBoundsException: -1 is out of bounds (min 0, max -1)
at ... ()
at Foo.$anonfun$new$1(DataViewEmpty.scala:24)
at chisel3.Data.$anonfun$$colon$eq$1(Data.scala:674)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at chisel3.experimental.prefix$.apply(prefix.scala:33)
at chisel3.Data.$colon$eq(Data.scala:674)
at Foo.(DataViewEmpty.scala:24)
at Main$.$anonfun$new$2(DataViewEmpty.scala:31)
at ... ()
at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.