From patchwork Tue Sep 25 23:19:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Go patch committed: Better error for switch on non-comparable type From: Ian Taylor X-Patchwork-Id: 186918 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Date: Tue, 25 Sep 2012 16:19:01 -0700 This patch to the Go frontend gives a better error message for a switch on a non-comparable type. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian diff -r 74d2d7d217d8 -r f47f5449a663 go/statements.cc --- a/go/statements.cc Sat Sep 22 00:17:10 2012 -0700 +++ b/go/statements.cc Mon Sep 24 15:20:45 2012 -0700 @@ -3846,6 +3846,16 @@ 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())