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

Constructors can have name clashes #78

Open
hecatia-elegua opened this issue Aug 26, 2023 · 0 comments
Open

Constructors can have name clashes #78

hecatia-elegua opened this issue Aug 26, 2023 · 0 comments

Comments

@hecatia-elegua
Copy link
Owner

Let's say you name your field e.g. offset or value. This will currently fail with some random error, because we already use these variable names and so they get shadowed.

field name and generated variable names clash
Funny enough, it's kinda like an user string injection attack.

To fix this, we either need to use more obscure names, like ____offset, or rename the passed-in field arguments at the top of the constructor to something which is not user-supplied, like arg_offset, arg_value. I like the second one more, since cargo expand should look more readable.

On the topic of readability, currently in constructors we do:

let raw_value = {
    //...
} | {
   //...
} | //...

Which should be more like:

let shifted_offset = { ... };
//...
let raw_value = shifted_offset | shifted_value | shifted_field3;
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

1 participant