-
Notifications
You must be signed in to change notification settings - Fork 302
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
[LANGUAGE] Add warning for unused variables #2394
Comments
Good idea! |
Love this idea! I'm not really familiar with the compiler (yet), but this seems like a great issue to dive into that code. Will try to implement this! |
I can imagine that @fRedelaar also wants to take this into account for the debugger (f.e. show a var in red in the list if ti is not used?) |
And this one I think could also be fun for you @jpelay, and not too hard? I do not think @fRedelaar will still do this as she has left the team a while ago |
For what it's worth, several editors I use will slightly gray out variables that aren't used rather than marking them in red; I like this as it is a subtle hint. There are some languages such as Go where unused variables are actually a compilation error, but I don't recommend Hedy implement this as I think it's quite user hostile. |
Yes, no problem :D |
Fixes #2394 (finally!!) by checking if declared variables are actually used, also fixes #4884 that was introduced here. Depends-On: #4880 **How to test** I have added a test for the exception. To see it in action on the front-end, run code that defines but not uses a variable, and observe you get a warning but the code still runs: <img width="1382" alt="image" src="https://github.com/hedyorg/hedy/assets/1003685/bb00c145-8d81-4e86-8ea1-316b0ae955c6"> Note that this PR needs #4880 to show the warning in the front-end!
My students often create a variable that they don't use. For example:
It would be nice to raise a Warning for each variable that was created but not used.
This could also help a lot in level 5 with if/else. I see a lot of students doing this:
This code always prints 'ai' because the check (
naam is gvr
) is always false. It can be hard for a student to discover why. Raising a warning would inform the student that they've not used the variablename
in the if-statement.The text was updated successfully, but these errors were encountered: