argotorg / solcore

experimental solidity compiler
13 stars 1 forks source link

Wrong wildcard handling in EmitCore #9

Closed mbenke closed 1 month ago

mbenke commented 3 months ago

Testcase test/examples/spec/badmatch.solc:

contract Option {
  data Option[a] = None | Some[a]

  function maybe(n, o) {
    match o {
      | Some[x] => return x;
      | _ => return n;
    };
  }

  function main() {
    return maybe(7, None);
  }
}

yields

    function maybe$Word (n : word, o : (unit + word)) -> word {
      match o with
      { inl $alt => revert "no match for: None"
        inr $alt => {   // Some[var_3]
                        let var_4 : word
                        var_4 := $alt
                        return var_4
                    }
      }

the call maybe(7, None) is also mistranslated to Yul (missing padding):

_v1 := maybe$Word(7, false)

should be sth like maybe$Word(7, false, $pad1)