-
Notifications
You must be signed in to change notification settings - Fork 199
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
Trying to understand enum resolution #1028
Trying to understand enum resolution #1028
Comments
@wader Thanks for sharing this. I agree that the behavior you demonstrate is very weird, but I'd say that the expected behavior is simple - only the It's a very good observation that the compiler doesn't flag any of the incorrect |
Ok thanks! and good tip to try compile to some typed language as a test. So as i understand it now the enum resolution is something like this:
|
Yes, looks good. Just noting that "look for enum" here:
should be trivial (no fallbacks, only the direct
(for |
Close this one and possibly split out the weirdness/bug into new issue? |
Yeah, makes sense. After seeing this - #1019 (comment), I realized that the KSC's component for resolving nested type references apparently misbehaves similarly as the component for resolving nested enums, and the faulty behavior you demonstrated on |
This is the same error as #786, but for enums, and when enum is specified with path it is full duplicate of #786. The recursive search of enum in parent types here: In the original example currently enums resolved as following: meta:
id: enum_resolve
seq:
- id: s0
type: u1
enum: e # ::e
- id: s1
type: u1
enum: a::e # ::a::e
- id: s2
type: u1
enum: a::a::e # ::a::e
- id: s3
type: u1
enum: b::e # ::e
- id: s4
type: u1
enum: b::b::e # ::e
- id: s5
type: u1
enum: a::b::e # ::e
- id: s6
type: u1
enum: b::a::e # ::a::e
types:
a:
enums:
e:
0: zero2
0x89: v2_x89
0x50: v2_x50
0x4e: v2_x4e
0x47: v2_x47
0x0d: v2_x0d
0x0a: v2_x0a
0x1a: v2_x1a
b: {}
enums:
e:
0: zero
0x89: v_x89
0x50: v_x50
0x4e: v_x4e
0x47: v_x47
0x0d: v_x0d
0x0a: v_x0a
0x1a: v_x1a |
This issue is not "full duplicate of #786". It's related, sure. But enums != types. I think it's perfectly possible to fix #786 and leave this one unresolved. So we should keep both issues open to make sure that we fix and verify both cases. |
I don't see what this contributes to this issue. It's the same example, with a bunch of extra enum members for some reason. We can already see clear enough what enums the compiler resolves the type paths into in the initial post #1028 (comment) because of the And the "absolute paths" that you added as comments don't make sense. You're making it look like |
@generalmimon, it is full duplicate when enum specified with a path. Because in that case enum is fixed in concrete type and how it would be resolved completely determined by the type resolution which suffer from #786.
Original description hard to understand without visualization. I've only added comments which shows to what enums paths currently resolves. They do not pretend to be valid Kaitai syntax. |
This commit also unify enum resolution in expression language and in `enum` keys Fixes kaitai-io/kaitai_struct#1028
This commit also unify enum resolution in expression language and in `enum` keys Fixes kaitai-io/kaitai_struct#1028
Hello, i'm trying to understand how enum:s are resolved. I assumed first that enum were resolve something like this:
::
, look up type first then look in enums.But when i trying some thing in webide and with ksdump things got confusing, for example:
Both ksdump and webide result in:
So seems to behave something like this: If last part(s?) of type namespace resolve to a type that has the enum then use it, otherwise ignore type namespace and just look in current types enums.
The text was updated successfully, but these errors were encountered: