hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
173 stars 18 forks source link

Constructors can have name clashes #78

Open hecatia-elegua opened 1 year ago

hecatia-elegua commented 1 year ago

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;