Skip to content

support switch-case statements #15504

@3esmit

Description

@3esmit

Abstract

Switch case is important for code cleanness. It's a common feature in all high level languages.

Motivation

While I undestand there is some complex edge cases to deal with on EVM for this control structure been implemented, it should start as simple as possible.

Specification

First iteration:

  • uint256
enum MyEnum { A, B, C };
// (...)
MyEnum b = MyEnum.B;
switch(uint(b)){
     default:
         emit MyEvent();
     case uint(MyEnum.A):
         //(...)
         break;
     case uint(MyEnum.B):
        //(...)
        break;
}

Second iteration:

  • enum type;

Third iteration:

  • custom errors

Fouth iteration:

  • complex structures

Whatever would cause a complexity or need more discussion to be porperly implemented should be left to a later iteration. In my example I used a default: without break;, if that would be difficult to solve, left it for a later iteration.

Backwards Compatibility

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions