How to pass ENUM type as argument to system Verilog task or function?

Let say i have enum defined below:


 package fruit_package{
  enum enum_fruit{
    APPLE = 0,
    MANGO = 1,
    BANANA = 2,
    ORANGE = 3};
  }

I have task that should take above enum as input argument and i need get index or value assigned for each fruit in enum declaration like 0 ,1 or 2 to be assigned to local variable fruit_val. My code looks like below:


 task fruit_config( enum enum_fruit fruit);
   int fruit_val;
   
   fruit_val = fruit;
 endtask

Is this correct way to do?

In reply to jackien:

Please use Code Tags. I have added them for you.

Did you read Section 6.19.4 Enumerated types in numerical expressions in the LRM? Did your code compile? Did you get a syntax error? Did your code run? Did your code give you a run-time error? Did your code work as expected? Did you get a different result than you expected?

It is difficult to provide assistance without additional information regarding the issue you are having.

In reply to jackien:

It is not the correct way to declare an enum. You need a typedef.