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

Invalid "switch"-statement generated for Java. #1161

Closed
ams-tschoening opened this issue Dec 7, 2016 · 2 comments
Closed

Invalid "switch"-statement generated for Java. #1161

ams-tschoening opened this issue Dec 7, 2016 · 2 comments
Assignees

Comments

@ams-tschoening
Copy link

ams-tschoening commented Dec 7, 2016

The following KSY is translated to invalid Java, but works in Ruby. The problem in Java is that the "(" are missing and the resulting statement simply doesn't compile. I know this KSY is ugly and such, was just a quick test and wanted to record that problem.

Is this by design and such complex statements simply not supported?

- id:       data
  type:
  switch-on: "( _parent.header.data_info_block.dif.has_vif    and
                _parent.header.value_info_block.vif.has_vife  and
              ((_parent.header.value_info_block.vif_exts[0].value == 0x1E) ? true : false)) ? 1 : 0"
  cases:
    1: fmt_oms_apl_vdb_data_compact_prof_with_reg
  size-eos: true

Resulting Java, where the indentation is mine to make the problem easier to recognize:

switch (_parent().header().dataInfoBlock().dif().hasVif()	&&
    	_parent().header().valueInfoBlock().vif().hasVife()	&&
        	_parent().header().valueInfoBlock().vifExts().get((int) 0).value() == 30 ? true : false ? 1 : 0) {
case 1: {
[...]
}

Error message:

Cannot switch on a value of type Object&Serializable&Comparable<?>. Only convertible int values, strings or enum variables are permitted

With proper parenthesis the code compiles:

switch ((	_parent().header().dataInfoBlock().dif().hasVif()	&&
        		_parent().header().valueInfoBlock().vif().hasVife()	&&
        	((	_parent().header().valueInfoBlock().vifExts().get((int) 0).value() == 30) ? true : false)) ? 1 : 0) {
case 1: {
[...]
}
@GreyCat GreyCat self-assigned this Dec 7, 2016
@GreyCat
Copy link
Member

GreyCat commented Dec 7, 2016

Thanks for the report! Will investigate soon.

@ams-tschoening
Copy link
Author

My fixes have been merged already, so this looks fixed for now.

@generalmimon generalmimon transferred this issue from kaitai-io/kaitai_struct_compiler Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants