PatternLanguage icon indicating copy to clipboard operation
PatternLanguage copied to clipboard

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

Open ZwipZwapZapony opened this issue 1 year ago • 3 comments

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 https://github.com/WerWolv/ImHex/issues/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 @ $;

ZwipZwapZapony avatar Apr 01 '24 14:04 ZwipZwapZapony

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.

paxcut avatar Apr 02 '24 03:04 paxcut

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.)

ZwipZwapZapony avatar Apr 02 '24 15:04 ZwipZwapZapony

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.

paxcut avatar Apr 02 '24 16:04 paxcut