diff mbox

Go patch committed: Tweak untyped nil error messages

Message ID mcrhaadiyxa.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Dec. 12, 2013, 8:42 p.m. UTC
This patch to the Go frontend tweaks the existing error messages about
use of untyped nil to do a better job when nil appears as the first
argument to the builtin append function.  This avoids an error about nil
not being a slice type--it's more useful to say that the problem is an
untyped nil.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 9931ebbea550 go/expressions.cc
--- a/go/expressions.cc	Thu Dec 12 12:13:34 2013 -0800
+++ b/go/expressions.cc	Thu Dec 12 12:40:57 2013 -0800
@@ -7310,7 +7310,11 @@ 
 	Type* slice_type = args->front()->type();
 	if (!slice_type->is_slice_type())
 	  {
-	    error_at(args->front()->location(), "argument 1 must be a slice");
+	    if (slice_type->is_nil_type())
+	      error_at(args->front()->location(), "use of untyped nil");
+	    else
+	      error_at(args->front()->location(),
+		       "argument 1 must be a slice");
 	    this->set_is_error();
 	    return this;
 	  }
@@ -8008,7 +8012,10 @@ 
 	const Expression_list* args = this->args();
 	if (args == NULL || args->empty())
 	  return Type::make_error_type();
-	return args->front()->type();
+	Type *ret = args->front()->type();
+	if (!ret->is_slice_type())
+	  return Type::make_error_type();
+	return ret;
       }
 
     case BUILTIN_REAL: