| 172 | } |
| 173 | |
| 174 | void validate_union_member(t_field* field) { |
| 175 | if (is_union_ && (!name_.empty())) { |
| 176 | union_validated_ = true; |
| 177 | |
| 178 | // 1) unions can't have required fields |
| 179 | // 2) union members are implicitly optional, otherwise bugs like THRIFT-3650 wait to happen |
| 180 | if (field->get_req() != t_field::T_OPTIONAL) { |
| 181 | // no warning on default requiredness, but do warn on anything else that is explicitly asked for |
| 182 | if(field->get_req() != t_field::T_OPT_IN_REQ_OUT) { |
| 183 | pwarning(1, |
| 184 | "Union %s field %s: union members must be optional, ignoring specified requiredness.\n", |
| 185 | name_.c_str(), |
| 186 | field->get_name().c_str()); |
| 187 | } |
| 188 | field->set_req(t_field::T_OPTIONAL); |
| 189 | } |
| 190 | |
| 191 | // unions may have up to one member defaulted, but not more |
| 192 | if (field->get_value() != nullptr) { |
| 193 | if (1 < ++members_with_value_) { |
| 194 | throw "Error: Field " + field->get_name() + " provides another default value for union " |
| 195 | + name_; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void validate_method_exception_field(t_field* field) { |
| 202 | if (is_method_xcepts_) { |