Skip to content

[BUG] Nested enum patterns aren't correctly matched #323

@Starexify

Description

@Starexify

In this haxe code:

class Test {
  static public function main() {
    var myTree = Tree.Node(Tree.Leaf("foo"), Tree.Node(Tree.Leaf("bar"), Tree.Leaf("foobar")));
    var match = switch (myTree) {
      case Tree.Leaf(_): "0";
      case Tree.Node(_, Tree.Leaf(_)): "1";
      case Tree.Node(_, Tree.Node(Tree.Leaf("bar"), _)): "2";
      case _: "3";
    }
    trace(match); // 2
  }
}

enum Tree {
  Leaf(v:String);
  Node(l:Tree, r:Tree);
}

The result should be 2. But for some reason in polymod it gives 1 back. Not sure what the cause is 100%, but it seems it's about the nested matching not working properly.

The manual might explain better this behavior: https://haxe.org/manual/lf-pattern-matching-enums.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions