This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Report errors for temporary statements
- 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, 21 Dec 2010 10:31:55 -0800
- Subject: Go patch committed: Report errors for temporary statements
The Go frontend assumed that a temporary statement was always correct
with respect to types. That is not the case: types are not checked
before temporary statements are created (temporary statements are used
to, e.g., split tuple assignments into single assignments). This patch
fixes the compiler to issue an error on a bad type rather than
crashing. Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 7f448375b9ac go/statements.cc
--- a/go/statements.cc Tue Dec 21 10:19:17 2010 -0800
+++ b/go/statements.cc Tue Dec 21 10:26:59 2010 -0800
@@ -350,7 +350,18 @@
Temporary_statement::do_check_types(Gogo*)
{
if (this->type_ != NULL && this->init_ != NULL)
- gcc_assert(Type::are_assignable(this->type_, this->init_->type(), NULL));
+ {
+ std::string reason;
+ if (!Type::are_assignable(this->type_, this->init_->type(), &reason))
+ {
+ if (reason.empty())
+ error_at(this->location(), "incompatible types in assignment");
+ else
+ error_at(this->location(), "incompatible types in assignment (%s)",
+ reason.c_str());
+ this->set_is_error();
+ }
+ }
}
// Return a tree.