Patchwork Go patch committed: Report errors for temporary statements

login
register
mail settings
Submitter Ian Taylor
Date Dec. 21, 2010, 6:31 p.m.
Message ID <mcrhbe7m0ys.fsf@google.com>
Download mbox | patch
Permalink /patch/76313/
State New
Headers show

Comments

Ian Taylor - Dec. 21, 2010, 6:31 p.m.
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

Patch

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.