Skip to content

fix: apply transformations to exprs in events#288

Closed
b-fein wants to merge 1 commit into
aspizu:mainfrom
b-fein:fix-constant-folding-in-events
Closed

fix: apply transformations to exprs in events#288
b-fein wants to merge 1 commit into
aspizu:mainfrom
b-fein:fix-constant-folding-in-events

Conversation

@b-fein
Copy link
Copy Markdown
Contributor

@b-fein b-fein commented May 21, 2026

Fixes #285

So far constant-folding was only applied to expressions appearing in statements. However, the OnLoudnessGt and OnTimerGt event types also contain expressions.

In case of negative number literals this resulted in a crash when generating the Scratch code, since such numbers are represented as Unop(Minus, 2) in the Goboscript AST whereas they are direct literals -2 in Scratch and thus no opcode for Minus exists.


I am unsure if this fix is complete or if the event-exprs should also be visited in some of the other passes. At least for the minimal example from the issue it now works.

@b-fein b-fein changed the title fix: apply constant-folding to exprs in events fix: apply transformations to exprs in events May 21, 2026
Fixes aspizu#285

So far constant-folding was only applied to expressions appearing in
statements. However, the OnLoudnessGt and OnTimerGt event types also
contain expressions.

In case of negative number literals this resulted in a crash when
generating the Scratch code, since such numbers are represented as
`Unop(Minus, 2)` in the Goboscript AST whereas they are direct literals
`-2` in Scratch and thus no opcode for Minus exists.
@b-fein b-fein force-pushed the fix-constant-folding-in-events branch from 117d0d2 to cecbad7 Compare May 21, 2026 07:28
@aspizu aspizu closed this May 22, 2026
@aspizu
Copy link
Copy Markdown
Owner

aspizu commented May 22, 2026

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: crash due to unreachable code reached

2 participants