chipsalliance / chipsalliance/chisel

Strange behavior with .elements on anonymous bundle

Open
#721 4 comments 1 reaction 0 assignees View on GitHub
bug question
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

Description

It seems that if you pass an anonymous bundle to a function without first assigning it to a val, reflection fails to find anything so its elements are empty.

```scala
import chisel3._

trait HasFoo { def foo: UInt }
class TestBundle extends Bundle with HasFoo {
val foo = UInt(32.W)
}

class TestModule extends Module {
val io = IO(new Bundle { })
def func(bun: Bundle): Unit = println(bun.elements)

// This one has empty elements!
func(new Bundle {
val foo = UInt(32.W)
})

func(new TestBundle)
func(new Bundle with HasFoo {
val foo = UInt(32.W)
})
func({
val b = new Bundle {
val foo = UInt(32.W)
}
b
})
}
```

This prints the following:
```scala
Map()
Map(foo -> chisel3.core.UInt@9)
Map(foo -> chisel3.core.UInt@b)
Map(foo -> chisel3.core.UInt@d)
```

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.