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

Remove warning about unused i in Java. #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ams-tschoening
Copy link
Contributor

This fixes kaitai-io/kaitai_struct#365 in a somewhat easy manner and can be improved in future if needed at all.

…ruct#365 in a somewhat easy manner and can be improved in future if needed at all.
@GreyCat
Copy link
Member

GreyCat commented Apr 10, 2018

What really bothers me about this solution is that it's a hack that effectively just fools the compiler warning system. If we'll accept it as a solution for now, we're bound to get more WTF questions from users later...

@ams-tschoening
Copy link
Contributor Author

ams-tschoening commented Apr 11, 2018

Do you really think one will have such a detailed look at the generated code in future? I don't unless I have problems or Eclipse marks my project with a warning sign. And currently there's no way to get rid of that sign unless one manually removes the usage of i after each and every new generation of code. I have 3 places in two files already and that started to annoy me.

Add a FIXME like in other cases already, linking to the issue. You can even output it in the generated Java code, so everyone with such a detailed look at the generated code can directly start working on a cleaner solution. ;-)

@generalmimon
Copy link
Member

FWIW, I recently fixed an issue with the unused i variable in Go - see the fix and the comment:

// FIXME: Go throws a fatal compile error when the `i` variable is not used (unused variables
// can only use the blank identifier `_`, see https://go.dev/doc/effective_go#blank), so we have
// to silence it like this. It would be nice to be able to analyze all expressions that appear
// in the loop body to decide whether to generate `for _ := range` or `for i := range` here, but
// that would be really difficult to do properly in KSC with the current architecture.
out.puts("_ = i")

In Go, an unused variable is even a fatal error (not a warning) and the .go source file will not compile, so this was clearly needed. I used an "approved" workaround taken directly from the Go docs, see https://go.dev/doc/effective_go#blank.

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.

The value of the local variable i is not used
4 participants