Enum degraded or spec changed with Build 540?

 
I made a simple test script.
//+------------------------------------------------------------------+
//|                                                    testEnum2.mq5 |
//+------------------------------------------------------------------+
#property script_show_inputs
input ENUM_DAY_OF_WEEK  InpDayOfWeek = SUNDAY; // Day Of Week
string NAME[7] =
  {
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
    Print(NAME[int(InpDayOfWeek)]); // Casting and no compile warning.
    int DayOfWeek = InpDayOfWeek;   // No casting and no compile warning. So enum type may be integer.
    Print(NAME[DayOfWeek]);         // No casting and no compile warning.
    Print(NAME[InpDayOfWeek]);      // No casting and no compile warning but compile error! Why?
  }
//+------------------------------------------------------------------+
Error message is:
'InpDayOfWeek' - integer expression expected testEnum2.mq5 24 16

Is enum type integer or not?
 
Is enum type integer or not?

MQL5 compiler controls type conversion - https://www.mql5.com/en/docs/basis/types/casting   

Alternative, you can try this code:

Print(EnumToString(InpDayOfWeek)); 
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Language Basics / Data Types / Typecasting - Documentation on MQL5
 
avoitenko:

MQL5 compiler controls type conversion - https://www.mql5.com/en/docs/basis/types/casting   

Alternative, you can try this code:

 

Thanks for your reply, and please excuse my misleading test script.
What I really want to know is whether enum type variable is available for index of array or not.
 

Enum type can be converted to integer type: 

Print(NAME[(int)InpDayOfWeek]);

But imagine that SUNDAY != 0 and MONDAY !=1 ..., and your code will not work.

You can use switch like this:

string DayOfWeekToString(ENUM_DAY_OF_WEEK day)
{
   switch(day)
   {
      case SUNDAY: return("Sunday");
      case MONDAY: return("Monday");

      ...

      default:return("");
   }
}

 

 

 
I am very thankful to you for your advice.

Anyway, the problem is not the content, but the form. 
My test code is only for example.
It could be compiled with previous build 5XX, but it can not be compiled with current build 540.
So, what I really want to know is whether this compile error is degradation or not.

Thank you.
 

Thanks a lot. It was fixed.

At this moment you better use casting like this

Print(NAME[(int)InpDayOfWeek]);

 

 
alexvd:

Thanks a lot. It was fixed.

At this moment you better use casting like this

 

I see. I don't check in the casting codes in my trunk of repository, and I will be waiting for the fixed build.

Thank you.