compiler: Better warning for switch on non-comparable type.
From-SVN: r191683
This commit is contained in:
parent
60478b9caf
commit
90f01468b4
1 changed files with 10 additions and 0 deletions
|
@ -3846,6 +3846,16 @@ Switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
|
|||
return new Constant_switch_statement(this->val_, this->clauses_,
|
||||
this->break_label_, loc);
|
||||
|
||||
if (this->val_ != NULL
|
||||
&& !this->val_->type()->is_comparable()
|
||||
&& !Type::are_compatible_for_comparison(true, this->val_->type(),
|
||||
Type::make_nil_type(), NULL))
|
||||
{
|
||||
error_at(this->val_->location(),
|
||||
"cannot switch on value whose type that may not be compared");
|
||||
return Statement::make_error_statement(loc);
|
||||
}
|
||||
|
||||
Block* b = new Block(enclosing, loc);
|
||||
|
||||
if (this->clauses_->empty())
|
||||
|
|
Loading…
Add table
Reference in a new issue