Unable to pattern match constructors inside a list #445

Closed
opened 2023-04-05 20:20:59 +09:00 by ghallak · 1 comment
ghallak commented 2023-04-05 20:20:59 +09:00 (Migrated from gitlab.com)

The following code will always return 2 regardless of what is passed to the function f.

contract C =
  entrypoint f(x : list(option(int))) =
      switch(x)
          (Some(a))::[] => 1
          _             => 2

Meanwhile, if the first line of the switch is changed to a::[] => 1 instead of (Some(a))::[] => 1, the pattern matching would work fine.

The following code will always return `2` regardless of what is passed to the function `f`. ``` contract C = entrypoint f(x : list(option(int))) = switch(x) (Some(a))::[] => 1 _ => 2 ``` Meanwhile, if the first line of the switch is changed to `a::[] => 1` instead of `(Some(a))::[] => 1`, the pattern matching would work fine.
zxq9 commented 2023-04-07 16:28:30 +09:00 (Migrated from gitlab.com)

Created by: radrow

It works correctly on master. The generated assembly also looks correct:

                          #{0 =>
                             [{'IS_NIL',{stack,0},{arg,0}},
                              {'JUMPIF',{stack,0},{immediate,4}}],
                            1 =>
                             [{'HD',{var,0},{arg,0}},
                              {'TL',{var,1},{arg,0}},
                              {'SWITCH_V2',
                               {var,0},
                               {immediate,4},
                               {immediate,2}}],
                            2 =>
                             [{'IS_NIL',{stack,0},{var,1}},
                              {'JUMPIF',{stack,0},{immediate,5}}],
                            3 => [{'RETURNR',{immediate,2}}],
                            4 => [{'RETURNR',{immediate,2}}],
                            5 => [{'RETURNR',{immediate,1}}]}}},
*Created by: radrow* It works correctly on master. The generated assembly also looks correct: ``` #{0 => [{'IS_NIL',{stack,0},{arg,0}}, {'JUMPIF',{stack,0},{immediate,4}}], 1 => [{'HD',{var,0},{arg,0}}, {'TL',{var,1},{arg,0}}, {'SWITCH_V2', {var,0}, {immediate,4}, {immediate,2}}], 2 => [{'IS_NIL',{stack,0},{var,1}}, {'JUMPIF',{stack,0},{immediate,5}}], 3 => [{'RETURNR',{immediate,2}}], 4 => [{'RETURNR',{immediate,2}}], 5 => [{'RETURNR',{immediate,1}}]}}}, ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#445