This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]