This patch to the Go frontend gives a better error message when setting
a const to nil. Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r d04de877d993 go/gogo.cc
--- a/go/gogo.cc Fri Mar 25 22:31:14 2011 -0700
+++ b/go/gogo.cc Fri Mar 25 22:41:02 2011 -0700
@@ -1527,7 +1527,9 @@
&& !ctype->is_boolean_type()
&& !ctype->is_string_type())
{
- if (!ctype->is_error())
+ if (ctype->is_nil_type())
+ error_at(constant->location(), "const initializer cannot be nil");
+ else if (!ctype->is_error())
error_at(constant->location(), "invalid constant type");
constant->set_error();
}