Skip to content

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Sep 8, 2024

It seems relatively new error, but the code was not changed since 2021...

Fixes errors like:

[info] - style_bad_num_inst_value *** FAILED ***
[info]   [style_bad_num_inst_value.ksy: /instances/size_of_foo/id:
[info]   	warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ]
[info]     did not equal
[info]   [style_bad_num_inst_value.ksy: /instances/size_of_foo:
[info]   	warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ] (SimpleMatchers.scala:34)

/instances/size_of_foo/id is not-existing path. Instances does not have id, the name of instance is its id.

Fixes kaitai-io/kaitai_struct#920.

Also fixes a couple of other errors

@generalmimon
Copy link
Member

generalmimon commented Sep 8, 2024

@Mingun:

It seems relatively new error

It is. I recently extended the formats_err test suite: kaitai-io/kaitai_struct_tests@c5f366f...0427d48

The tests you're fixing here were added in kaitai-io/kaitai_struct_tests@c911e0a to demonstrate kaitai-io/kaitai_struct#920. So ideally you should add Fixes https://github.com/kaitai-io/kaitai_struct/issues/920 to the PR description and commit message.

@Mingun Mingun marked this pull request as draft September 8, 2024 11:11
@Mingun Mingun force-pushed the fix-excess-id-in-path branch from 533c134 to 4ed5981 Compare September 8, 2024 11:53
@Mingun Mingun marked this pull request as ready for review September 8, 2024 11:54
@Mingun
Copy link
Contributor Author

Mingun commented Sep 10, 2024

@generalmimon, could you look again? This PR fixes 13 errors

@Mingun Mingun force-pushed the fix-excess-id-in-path branch 2 times, most recently from d2a946b to af582ae Compare August 21, 2025 18:34
@Mingun
Copy link
Contributor Author

Mingun commented Aug 22, 2025

@GreyCat, @generalmimon , this PR reduces error count from currently 54 to 42. It is small win, do you mind to merge it?

Copy link
Member

@GreyCat GreyCat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, looks good to me and relatively straightforward fix! Thanks @Mingun!

@generalmimon, do you have any concerns or shall we merge this?

Copy link
Member

@generalmimon generalmimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine too, it indeed fixes some of the test failures.

You know I'm not a big fan of adding comments unless it's absolutely necessary, but if you do, I'd prefer them to make sense...


def resolveUserType(curClass: ClassSpec, dataType: DataType, path: List[String]): Iterable[CompilationProblem] = {
/**
* Resolves the type of the `dataType` of an attribute defined in `curClass`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what "the type of the dataType" means, maybe just

Suggested change
* Resolves the type of the `dataType` of an attribute defined in `curClass`.
* Resolves the `dataType` of an attribute defined in `curClass`.

...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is reference to user-defined class (and maybe to built-in type? Don't remember. Affected by the lack of documentation, so I cannot agree with your statement that something is obvious here...). By the way, the whole procedure looks complicated and buggy, but it is fixed in #309

Mingun added 4 commits August 23, 2025 19:17
Fixes kaitai-io/kaitai_struct#920

Error count: 54 -> 50 (-4). Fixed:

[info] - style_bad_len_inst_pos *** FAILED ***
[info]   [style_bad_len_inst_pos.ksy: /instances/size_of_foo/id:
[info]          warning: use `len_foo` instead of `size_of_foo`, given that it's only used as a byte size of `foo` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ]
[info]     did not equal
[info]   [style_bad_len_inst_pos.ksy: /instances/size_of_foo:
[info]          warning: use `len_foo` instead of `size_of_foo`, given that it's only used as a byte size of `foo` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ] (SimpleMatchers.scala:34)
[info] - style_bad_len_inst_value *** FAILED ***
[info]   [style_bad_len_inst_value.ksy: /instances/size_of_foo/id:
[info]          warning: use `len_foo` instead of `size_of_foo`, given that it's only used as a byte size of `foo` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ]
[info]     did not equal
[info]   [style_bad_len_inst_value.ksy: /instances/size_of_foo:
[info]          warning: use `len_foo` instead of `size_of_foo`, given that it's only used as a byte size of `foo` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ] (SimpleMatchers.scala:34)
[info] - style_bad_num_inst_pos *** FAILED ***
[info]   [style_bad_num_inst_pos.ksy: /instances/size_of_foo/id:
[info]          warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ]
[info]     did not equal
[info]   [style_bad_num_inst_pos.ksy: /instances/size_of_foo:
[info]          warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ] (SimpleMatchers.scala:34)
[info] - style_bad_num_inst_value *** FAILED ***
[info]   [style_bad_num_inst_value.ksy: /instances/size_of_foo/id:
[info]          warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ]
[info]     did not equal
[info]   [style_bad_num_inst_value.ksy: /instances/size_of_foo:
[info]          warning: use `num_foos` instead of `size_of_foo`, given that it's only used as repeat count of `foos` (see https://doc.kaitai.io/ksy_style_guide.html#attr-id)
[info]   ] (SimpleMatchers.scala:34)
…TH" errors

Error count: 50 -> 43 (-7). Fixed:

[info] - id_clash_params_vs_inst_pos *** FAILED ***
[info]   [id_clash_params_vs_inst_pos.ksy: /instances/foo:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/0
[info]   ]
[info]     did not equal
[info]   [id_clash_params_vs_inst_pos.ksy: /instances/foo:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/0/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_clash_params_vs_inst_value *** FAILED ***
[info]   [id_clash_params_vs_inst_value.ksy: /instances/bar:
[info]          error: duplicate attribute ID 'bar', previously defined at /params/1
[info]   ]
[info]     did not equal
[info]   [id_clash_params_vs_inst_value.ksy: /instances/bar:
[info]          error: duplicate attribute ID 'bar', previously defined at /params/1/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_clash_params_vs_seq *** FAILED ***
[info]   [id_clash_params_vs_seq.ksy: /seq/0:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/1
[info]   ]
[info]     did not equal
[info]   [id_clash_params_vs_seq.ksy: /seq/0/id:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/1/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_clash_seq_vs_inst_pos *** FAILED ***
[info]   [id_clash_seq_vs_inst_pos.ksy: /instances/foo:
[info]          error: duplicate attribute ID 'foo', previously defined at /seq/0
[info]   ]
[info]     did not equal
[info]   [id_clash_seq_vs_inst_pos.ksy: /instances/foo:
[info]          error: duplicate attribute ID 'foo', previously defined at /seq/0/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_clash_seq_vs_inst_value *** FAILED ***
[info]   [id_clash_seq_vs_inst_value.ksy: /instances/bar:
[info]          error: duplicate attribute ID 'bar', previously defined at /seq/1
[info]   ]
[info]     did not equal
[info]   [id_clash_seq_vs_inst_value.ksy: /instances/bar:
[info]          error: duplicate attribute ID 'bar', previously defined at /seq/1/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_dup_params *** FAILED ***
[info]   [id_dup_params.ksy: /params/2:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/0
[info]   ]
[info]     did not equal
[info]   [id_dup_params.ksy: /params/2/id:
[info]          error: duplicate attribute ID 'foo', previously defined at /params/0/id
[info]   ] (SimpleMatchers.scala:34)
[info] - id_dup_seq *** FAILED ***
[info]   [id_dup_seq.ksy: /seq/2:
[info]          error: duplicate attribute ID 'foo', previously defined at /seq/0
[info]   ]
[info]     did not equal
[info]   [id_dup_seq.ksy: /seq/2/id:
[info]          error: duplicate attribute ID 'foo', previously defined at /seq/0/id
[info]   ] (SimpleMatchers.scala:34)
Error count: 43 -> 42 (-1). Fixed:

[info] - type_unknown_switch *** FAILED ***
[info]   [type_unknown_switch.ksy: /seq/0/type/cases/IntNum(42)/type:
[info]          error: unable to find type 'some_unknown_name', searching from type_unknown_switch
[info]   ]
[info]     did not equal
[info]   [type_unknown_switch.ksy: /seq/0/type/cases/IntNum(42):
[info]          error: unable to find type 'some_unknown_name', searching from type_unknown_switch
[info]   ] (SimpleMatchers.scala:34)
@Mingun Mingun force-pushed the fix-excess-id-in-path branch from af582ae to b868509 Compare August 23, 2025 14:17
@Mingun
Copy link
Contributor Author

Mingun commented Aug 23, 2025

@generalmimon, your suggestion applied

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.

Path in warnings related to ids of instances is wrong

3 participants