Branch: Tag:

2013-11-08

2013-11-08 18:07:07 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Warn about case values that are not enumerable.

Constant objects and the like are not a good idea to have in
case statements, since their ordering will depend on (among
other things) compilation order, which means that they will
currently likely break for dumped programs.

4013:       case F_CASE_RANGE:    if (CDR(n) && CAR(n) && !TEST_COMPAT(0,6)) { +  fix_type_field(CAR(n)); +  fix_type_field(CDR(n));    /* case 1 .. 2: */    if (!match_types(CAR(n)->type, CDR(n)->type)) {    if (!match_types(CAR(n)->type, int_type_string) ||
4045:    }    }    } +  if (CDR(n) && (Pike_compiler->compiler_pass == 2)) { +  fix_type_field(CDR(n)); +  if (!match_types(CDR(n)->type, enumerable_type_string)) { +  yytype_report(REPORT_WARNING, +  NULL, 0, enumerable_type_string, +  NULL, 0, CDR(n)->type, +  0, "Case value is not an enumerable type."); +  } +  }    /* FALL_THROUGH */    case F_CASE: -  +  if (CAR(n) && (Pike_compiler->compiler_pass == 2)) { +  fix_type_field(CAR(n)); +  if (!match_types(CAR(n)->type, enumerable_type_string)) { +  yytype_report(REPORT_WARNING, +  NULL, 0, enumerable_type_string, +  NULL, 0, CAR(n)->type, +  0, "Case value is not an enumerable type."); +  } +  } +  /* FALL_THROUGH */    case F_INC_LOOP:    case F_DEC_LOOP:    case F_DEC_NEQ_LOOP: