This is a known bug of Arduino builder, if you have functions before structs, classes or enums in sketch.
The sketch:
void foo() {
}
enum class CYCLE { TypeA, TypeB };
String cycleToString (CYCLE cycle) {
if (cycle == CYCLE::TypeA) {
return "TypeA";
}
else if (cycle == CYCLE::TypeB) {
return "TypeB";
}
return "Undefined";
}
void setup() {
}
void loop() {
}
is processed to this .cpp file
#include <Arduino.h>
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo();
#line 7 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
String cycleToString(CYCLE cycle);
#line 17 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void setup();
#line 22 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void loop();
#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo() {
}
enum class CYCLE { TypeA, TypeB };
String cycleToString (CYCLE cycle) {
if (cycle == CYCLE::TypeA) {
return "TypeA";
}
else if (cycle == CYCLE::TypeB) {
return "TypeB";
}
return "Undefined";
}
void setup() {
}
void loop() {
}
as you can see the forward declarations of functions are before the first function so before the enum.
The workaround for this bug is to follow good practice and declare all the structs, enums and classes before the first function definition.