This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Better error for switch on non-comparable type
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Tue, 25 Sep 2012 16:19:01 -0700
- Subject: Go patch committed: Better error for switch on non-comparable type
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())