Maths doesn't promote to destination type
- Dominant language
- Scala
- Stars
- 279
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
So Given
```
word CurrentNumMovesLeft
CurrentNumMovesLeft = 148 << 6
```
You then get
```
LDA #0
STA CurrentNumMovesLeft
LDA #0
STA CurrentNumMovesLeft + 1
```
Which is wrong. You have to do
`; CurrentNumMovesLeft = word(148) << 6`
Which then gets you
```
LDA #0
STA CurrentNumMovesLeft
LDA #$25
STA CurrentNumMovesLeft + 1
```
It should detect that the destination is a word and limit the value to the size of the destination without having everything cast. It should also perform all maths at the highest needed and then only truncate at the end.
Contributor guide
Research direction
Use the issue's word assignment example as the reproduction case, comparing the generated assembly with and without the explicit word cast. Trace the compiler's type promotion and arithmetic evaluation entry points, then verify that destination-width truncation happens only at the end and that the generated code preserves the expected high byte.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100