Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: only wrap single struct param in a tuple #368

Merged
merged 1 commit into from
Aug 11, 2021

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Aug 10, 2021

Motivation

This is a follow up for #363 which introduced invalid encoding if the function has not a single struct parameter.
The reason why this is a bit error prone is due the token flattening that takes place during encoding of the input params where the outmost Tuple layer gets removed. This is intentionally because all function arguments are passed to the method_hash function as tuple which adds the Tuple layer in the first place.
However, if the function input is a single struct, prior to #363 the param would be ((input)) which is not a rust tuple but input itself is, so flatten_tokens would later strip away the outmost Tuple layer of the input itself, instead of the additional Tuple layer that would have been added if ((input)) where a rust tuple.

So in #363 I attempted to fix this by enforcing tuple encoding((input)) if the param is a tuple, however I did not understand that this was the entire edge case so #363 results in invalid encoding for multiple params (which enforce tuple encoding)

Solution

Since the edge case is:

  • struct input
  • len(input) == 1
    we can add this condition in to the match arm

@gakonst gakonst merged commit 109a6b8 into gakonst:master Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants