@@ -79,6 +79,8 @@ class smv_typecheckt:public typecheckt
7979 bool do_spec;
8080
8181 smv_ranget convert_type (const typet &);
82+ static bool is_contained_in (irep_idt, const enumeration_typet &);
83+
8284 void convert (smv_parse_treet::modulet::itemt &);
8385 void typecheck (smv_parse_treet::modulet::itemt &);
8486 void typecheck_expr_rec (exprt &, const typet &, modet);
@@ -137,6 +139,26 @@ class smv_typecheckt:public typecheckt
137139
138140/* ******************************************************************\
139141
142+ Function: smv_typecheckt::is_contained_in
143+
144+ Inputs:
145+
146+ Outputs:
147+
148+ Purpose:
149+
150+ \*******************************************************************/
151+
152+ bool smv_typecheckt::is_contained_in (irep_idt id, const enumeration_typet &type)
153+ {
154+ for (auto &element : type.elements ())
155+ if (element.id () == id)
156+ return true ;
157+ return false ;
158+ }
159+
160+ /* ******************************************************************\
161+
140162Function: smv_typecheckt::convert_ports
141163
142164 Inputs:
@@ -749,10 +771,11 @@ void smv_typecheckt::typecheck_expr_rec(
749771 }
750772 else if (expr.id ()==ID_constant)
751773 {
774+ const auto value = to_constant_expr (expr).get_value ();
775+
752776 if (expr.type ().id ()==ID_integer)
753777 {
754- const std::string &value=expr.get_string (ID_value);
755- mp_integer int_value=string2integer (value);
778+ mp_integer int_value = string2integer (id2string (value));
756779
757780 if (dest_type.is_nil ())
758781 {
@@ -796,6 +819,12 @@ void smv_typecheckt::typecheck_expr_rec(
796819 {
797820 if (dest_type.id () == ID_enumeration)
798821 {
822+ if (!is_contained_in (value, to_enumeration_type (dest_type)))
823+ {
824+ throw errort ().with_location (expr.find_source_location ())
825+ << " enum " << value << " not a member of " << to_string (dest_type);
826+ }
827+
799828 if (to_enumeration_type (expr.type ()).elements ().empty ())
800829 expr.type () = dest_type;
801830 }
0 commit comments