Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring event block after "on-start" #5752

Closed
wants to merge 1 commit into from

Conversation

sae220
Copy link
Contributor

@sae220 sae220 commented Jul 29, 2024

#5700

This is because unfortunately the code generation can end up placing the event handler code on top of the "on start" code, and so we might end up with an undefined variable:

block
block

before
before

after
after

@microbit-carlos @abchatra

@abchatra
Copy link
Collaborator

abchatra commented Aug 8, 2024

Sorry for the delay. I will review this week

@abchatra abchatra requested a review from riknoll August 23, 2024 22:18
@riknoll
Copy link
Member

riknoll commented Aug 27, 2024

we hoist event handlers above on-start intentionally because people can write code that pauses inside of on-start.

for example, take a look at this program:

microbit-screenshot (31)

if we were to register the event handler after on-start, it ends up breaking this program because that while loop will never finish executing.

i agree that both error scenarios are confusing on this one, but i think not hoisting the event handler is worse. i think the better fix would be to add a warning when variables are used in event handlers that don't have afterOnStart, similar to how we give a warning if a variable is never assigned in blocks

@microbit-carlos
Copy link
Collaborator

Alternatively we could leave the pin event handler with a "normal pin dropdown" (what we had in MakeCode v6), instead of the shadow block. That way users cannot drop a variable into the handler that could be undefined.

@abchatra
Copy link
Collaborator

Let's close this PR based on Richard's comments. Thanks for @sae220 for all the work.

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.

4 participants