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

[LANGUAGE] Add warning for unused variables #2394

Closed
OnnoEbbens opened this issue Mar 31, 2022 · 6 comments · Fixed by #4881
Closed

[LANGUAGE] Add warning for unused variables #2394

OnnoEbbens opened this issue Mar 31, 2022 · 6 comments · Fixed by #4881
Assignees
Labels
language Issues related to the Hedy language

Comments

@OnnoEbbens
Copy link
Collaborator

My students often create a variable that they don't use. For example:

name is Fatih
print 'my name is Fatih'

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:

name is print 'what is your name?'
if naam is gvr print 'ok' else print 'ai'

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 variable name in the if-statement.

@MarleenGilsing
Copy link
Collaborator

Good idea!

@TiBiBa TiBiBa self-assigned this Mar 31, 2022
@TiBiBa
Copy link
Collaborator

TiBiBa commented Mar 31, 2022

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!

@Felienne
Copy link
Member

Felienne commented Apr 4, 2022

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?)

@TiBiBa TiBiBa assigned redelaar and unassigned TiBiBa Apr 5, 2022
@Felienne
Copy link
Member

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

@nycdotnet
Copy link
Contributor

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.

@jpelay
Copy link
Member

jpelay commented Oct 28, 2022

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

Yes, no problem :D

@Felienne Felienne changed the title Add warning for unused variables [Language idea] [LANGUAGE] Add warning for unused variables Sep 23, 2023
@Felienne Felienne moved this to ToBeDiscussed in Hedy organization board Sep 23, 2023
@Felienne Felienne added the language Issues related to the Hedy language label Sep 25, 2023
@Felienne Felienne self-assigned this Oct 31, 2023
@Felienne Felienne moved this from ToBeDiscussed to In Progress in Hedy organization board Nov 14, 2023
@Felienne Felienne moved this from In Progress to Done in Hedy organization board Dec 11, 2023
@mergify mergify bot closed this as completed in #4881 Dec 13, 2023
mergify bot pushed a commit that referenced this issue Dec 13, 2023
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!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Issues related to the Hedy language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants