chipsalliance / chipsalliance/chisel

A name followed by the same name with an trailing underscore results in `java.lang.NumberFormatException`

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

Description

**Type of issue**: Bug Report

**Please provide the steps to reproduce the problem:**

Construct hardware with some name, then construct additional hardware with the same name followed by an underscore. For example:

```scala
package foobar

import chisel3._

class Foo extends Module {
val bar = RegInit(false.B)
val bar_ = RegInit(false.B)
}

object EmitFoo {
def main(args: Array[String]): Unit = {
(new chisel3.stage.ChiselStage).emitVerilog(new Foo)
}
}
```

**What is the current behavior?**

Fails, throws `java.lang.NumberFormatException`.

```
[info] running foobar.EmitFoo
[error] (run-main-0) java.lang.NumberFormatException: For input string: ""
[error] java.lang.NumberFormatException: For input string: ""
[error] at ... ()
[error] at ... ()
[error] at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
[error] stack trace is suppressed; run last Compile / bgRunMain for the full output
[error] Nonzero exit code: 1
[error] (Compile / runMain) Nonzero exit code: 1
```

**What is the expected behavior?**

Construct the appropriate hardware.

**Please tell us about your environment:**

Chisel version 3.5.6 and 3.6.0-RC2. Reproducible in the official Scastie environment of 3.6.0-RC2.

Does not reproduce in Chisel 3.5.5 and 3.5.4.

Official 3.6.0-RC2 Scastie:
https://scastie.scala-lang.org/jWaVv1vsSyGSG5I7Rvw9dw

3.5.6 Scastie:
https://scastie.scala-lang.org/fuqkiNCBTkCtnRWgJlLI2Q

**Other Information**

**What is the use case for changing the behavior?**

Chisel fails with a completely opaque error message.

Contributor guide

Open the contributing guide

Research direction

Start with the Foo and EmitFoo reproducer, using ChiselStage.emitVerilog to confirm the failure when bar is followed by bar_. Trace the name handling that leads to NumberFormatException and compare behavior with Chisel 3.5.5. Done means the hardware is emitted successfully for the reproducer without the exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.