Error returning value from switch case?

after coding a custom event in AS3, I ran into a curious problem:

override public function toString():String
    {
    switch  (type)
            {
            case CHANGE:    return formatToString("HistoryEvent", "type", "action", "name", "data");
            case ABILITY:   return formatToString("HistoryEvent", "type", "undoable", "redoable");
            }
    }

the above code returns the following compile time error:

1170: the function does not return a value.

I can easily fix the problem by adding return null;functions at the end, but this is redundant, and it annoys me that this is the only solution.

why is the value returned from a switch case not seen by the compiler? is this a problem specific to the AS3 compiler, or am I really trying to do something here so completely dangerous and unfavorable that it obscures the countercultists around the world.

+3
source share
2 answers

, , . . default: return null; switch , return null .

+3

switch.

0

Source: https://habr.com/ru/post/1786372/


All Articles