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

Struct member access doesn't work on the left-hand side of +=, nor the left-hand side within patterns #87

Open
ZwipZwapZapony opened this issue Apr 1, 2024 · 3 comments

Comments

@ZwipZwapZapony
Copy link

Using the version of Pattern Language in ImHex v1.33.2, if abc is a struct, then abc.var is a little picky on the left-hand side of assignments in the global scope, and very picky on the left-hand side of assignments within structs (regardless of whether abc is a global struct or a member of the struct currently being parsed).
(This might explain half of WerWolv/ImHex#1599 ?)


Note the //This does not work comments in...

import std.io;

struct GlobalStruct {
    u8 var = 10;
};
GlobalStruct abc;

abc.var = 15; //This works
//abc.var += 5; //This does not work
abc.var = abc.var + 5; //This works
std::print("{}",abc.var+2); //This works
u8 global_var1 = abc.var + 5 [[export]]; //This works
u8 global_var2 = 0 [[comment(abc.var+3),export]]; //This works

struct MyStruct {
    //abc.var = 50; //This does not work
    //abc.var += 5; //This does not work
    //abc.var = abc.var + 5; //This does not work
    std::print("{}",abc.var+2); //This works
    u8 struct_var1 = abc.var + 5 [[export]]; //This works
    u8 struct_var2 [[comment(abc.var+3),export]]; //This works

    struct_var1 = 70; //This works
    //this.struct_var1 = 75; //This does not work
    u8 struct_var3 = this.struct_var1 + 4 [[export]]; //This works, meaning that "this.struct_var1" above isn't incorrect
};

MyStruct data @ $;
@paxcut
Copy link
Contributor

paxcut commented Apr 2, 2024

the only problem i see in your example code that wasn't already known is that += is not working as it should. there is a known problem using the dot operator on the left side of assignments inside structures that needs to be looked at. maybe the title of this issue should be changed to specify that the problem occurs only inside structures.

@ZwipZwapZapony
Copy link
Author

ZwipZwapZapony commented Apr 2, 2024

the only problem i see in your example code that wasn't already known [...]

I tried to look first, but I didn't find an open issue about this in neither ImHex's nor PatternLanguage's repositories.

[...] is that += is not working as it should. [...] maybe the title of this issue should be changed to specify that the problem occurs only inside structures.

abc += 5; works fine in the global scope and in structs, so it's specifically due to abc.var on the left-hand side that it's not working. (Which is probably more so tied to the += operator than to abc.var itself, yes - but that's still a problem related to abc.var that also happens outside of structs.)

@paxcut
Copy link
Contributor

paxcut commented Apr 2, 2024

I'm sorry, I didn't express myself correctly. By known problem I meant known as a result of out recent exchanges as I mentioned it in one of the issues you opened. My suggestion of the name change is only to help the person who tries to fix it find the problem faster. The fact that

abc.var = abc.var + 5; 

works outside of the struct seems to indicate that there is no problem with the dot operator used on the right hand side of an assignment and that += not working must be unrelated since both should mean the same thing.

@ZwipZwapZapony ZwipZwapZapony changed the title Struct access doesn't work properly on the left-hand side of assignments Struct member access doesn't work on the left-hand side of "+=", nor within patterns Apr 8, 2024
@ZwipZwapZapony ZwipZwapZapony changed the title Struct member access doesn't work on the left-hand side of "+=", nor within patterns Struct member access doesn't work on the left-hand side of +=, nor the left-hand side within patterns Apr 8, 2024
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

No branches or pull requests

2 participants