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

The value of the local variable i is not used #365

Open
ams-tschoening opened this issue Feb 23, 2018 · 2 comments · May be fixed by kaitai-io/kaitai_struct_compiler#135
Open

The value of the local variable i is not used #365

ams-tschoening opened this issue Feb 23, 2018 · 2 comments · May be fixed by kaitai-io/kaitai_struct_compiler#135

Comments

@ams-tschoening
Copy link

I have the following KSY:

  - id:       decrypted_if
    type:     fmt_oms_apl_vdb
    repeat:       until
    repeat-until: _.next_isnt_vdb
    if:       not   next_isnt_vdb

leading to the following Java:

        if (!(nextIsntVdb())) {
            this.decryptedIf = new ArrayList<FmtOmsAplVdb>();
            {
                FmtOmsAplVdb _it;
                int i = 0;
                do {
                    _it = new FmtOmsAplVdb(this._io, this, _root);
                    this.decryptedIf.add(_it);
                    i++;
                } while (!(_it.nextIsntVdb()));
            }
        }

i is not read and therefore Eclipse provides a warning about that. Is there some way the compiler could recognize that and either don't output i at all or add @SuppressWarnings("unused"). The problem with the latter is of course that if i is read the suppression is wrong and Eclipse warns about that. :-)

@KOLANICH
Copy link

If I know right, there is: i is used for _index. If _index is not used, i is not used.

@GreyCat
Copy link
Member

GreyCat commented Feb 23, 2018

It's not very trivial to do that, but certainly possible. Probably we'll need some precompile-level machinery that will derive whether a particular repeated attribute uses _index or not, and then will use that knowledge to generate that i conditionally.

ams-tschoening pushed a commit to ams-ts-kaitai/compiler that referenced this issue Mar 30, 2018
…ruct#365 in a somewhat easy manner and can be improved in future if needed at all.
ams-tschoening pushed a commit to ams-ts-kaitai/compiler that referenced this issue Mar 30, 2018
…ruct#365 in a somewhat easy manner and can be improved in future if needed at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants