gccrs doesn't start numbering new enum discriminant from last specified discriminant
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
Summary
From gccrs zulip, compiler-development channel, issue 3351 thread:
From Jasmine
there is also another bug
enum Foo {
Bar,
Bob,
Qaz = -1,
Babara,
}
fn main() {}
rustc will error out since Bar = Babara = 0, but gccrs (via rust_debug), recognizes that Babara is 3, and doesnt crash. Bob in this case will take on value 1, so im not sure why Babara is not equal to Qaz + 1
from Philip Herron:
Ah good find iirc there is a chunk of code in HIR lowering to explicitly set the discrimiant values which will need changed as well. This was added just to simplify things for us early on but yeah it will have overriden the values. Actually you know i bet the discriminants are actually just using the variant index from the ADTType and ignoring the specified discrimiant
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the HIR lowering code that explicitly assigns discriminant values, then inspect how ADTType or variant indexes are used. Use the enum example to verify that Babara follows Qaz + 1 and that duplicate discriminants are handled consistently with rustc.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100