kaitai_struct_compiler icon indicating copy to clipboard operation
kaitai_struct_compiler copied to clipboard

Remove warning about unused i in Java.

Open ams-tschoening opened this issue 7 years ago • 3 comments

This fixes https://github.com/kaitai-io/kaitai_struct/issues/365 in a somewhat easy manner and can be improved in future if needed at all.

ams-tschoening avatar Mar 30 '18 07:03 ams-tschoening

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...

GreyCat avatar Apr 10 '18 22:04 GreyCat

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. ;-)

ams-tschoening avatar Apr 11 '18 06:04 ams-tschoening

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

https://github.com/kaitai-io/kaitai_struct_compiler/blob/8913518145cb1dc6efb3b6b40d115cb0a256c813/shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala#L324-L329

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.

generalmimon avatar Jul 01 '22 15:07 generalmimon