# \`match\` enum with Int64 param

**URL:** <https://community.haxe.org/t/match-enum-with-int64-param/4421>\
**Category:** Haxe\
**Created:** [October 6, 2024, 7:33pm UTC](https://community.haxe.org/t/match-enum-with-int64-param/4421 "2024-10-06T19:33:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zagortenej](https://community.haxe.org/user_avatar/community.haxe.org/zagortenej/32/848_2.png) [@zagortenej](https://community.haxe.org/u/zagortenej)\
**Post date:** [October 6, 2024, 7:33pm UTC](https://community.haxe.org/t/match-enum-with-int64-param/4421/1 "2024-10-06T19:33:19Z")

</div>

I expected to be able to `match()` enum value with `Int64` parameter by using `Int` literal (because Int64 has @from Int) but it is not the case: [Try Haxe!](https://try.haxe.org/#bd6eF429)

Is this the way things supposed to be or am I missing something?

Also, you can’t `match( FOO( Int64.ofInt(42) ) )`, but that’s would be a bit cumbersome anyways even if possible.

---

<div class="post-metadata">

**Author:** ![neimanpinchas](https://community.haxe.org/user_avatar/community.haxe.org/neimanpinchas/32/2348_2.png) [@neimanpinchas](https://community.haxe.org/u/neimanpinchas)\
**Post date:** [April 9, 2025, 11:01pm UTC](https://community.haxe.org/t/match-enum-with-int64-param/4421/3 "2025-04-09T23:01:40Z")

</div>

To clarify the root of the problem is that there is no such thing like a Int64 constant, and .match() will only accept constants, not an expression that would return a value or some implicit conversion.

I thing the reason behind is that .match works at compile time, but not sure.

But you are right that numeric literals should be valid in place of any bitness, or a Int64 kind of literal should be intriduced.

---

<div class="post-metadata">

**Author:** ![nanjizal](https://community.haxe.org/user_avatar/community.haxe.org/nanjizal/32/239_2.png) [@nanjizal](https://community.haxe.org/u/nanjizal)\
**Post date:** [April 27, 2025, 10:47am UTC](https://community.haxe.org/t/match-enum-with-int64-param/4421/4 "2025-04-27T10:47:16Z")

</div>

Since `match` implementation differs between native and via different libraries it is probably better to stick with the more established switch method when possible. Perhaps there is a cleaner approach but this works.

```haxe
enum Foo {
  FOO( v : haxe.Int64 );
  BAR;
}

class Test {
  static function main() {
    var nv1 = FOO(42);
    var nv2 = FOO(44);
    
    checker(nv1);
    checker(nv2);
  }
}
function checker( v ){
  var n64 = haxe.Int64.toInt(42);
  var found: Bool = switch( v ){
			case FOO(val):
                          trace(' FOO found');
                          switch( v ){
      	                       case val == n64 => true:
      		                   trace('val is $n64');
      		                   trace( v );	
      		                   true;
                               case _:
      		                   trace('FOO does not contain $n64');
         	                   false;
                          }
               case BAR:
      	             false;
    }
    trace( 'found $found' );
}

```

sorry not sure how to get formatting correct.  
Generally it is much easier to deal with more complex compile time type matching using the flexibility of switch statements, just it may require more checking manual and some experimentation. Match is a more recent addition and likely more suited to string regex, especially as it makes use of native or a lib implementations that will not be as compile time flexible, ie not as closely aligned with haxe compilers type manipulation.
