compiler: avoid generating unnamed bool type descriptor

We were generating it in cases where a boolean expression was
converted directly to an empty interface type.

Fixes golang/go#40152

Change-Id: I59e0f184b46fa1c1309b322b4b14e93f3fb0436f
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/242002
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index deac874..327f940 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -6041,10 +6041,7 @@
 						     &right_nc, location,
 						     &result))
 	      return this;
-	    return Expression::make_cast(Type::make_boolean_type(),
-					 Expression::make_boolean(result,
-								  location),
-					 location);
+	    return Expression::make_boolean(result, location);
 	  }
 	else
 	  {
diff --git a/go/gogo.cc b/go/gogo.cc
index 212ef45..c1021e5 100644
--- a/go/gogo.cc
+++ b/go/gogo.cc
@@ -3309,7 +3309,11 @@
       && be->boolean_constant_value(&bval)
       && (be->op() == OPERATOR_ANDAND
           || be->op() == OPERATOR_OROR))
-    *pexpr = Expression::make_boolean(bval, be->location());
+    {
+      *pexpr = Expression::make_boolean(bval, be->location());
+      Type_context context(NULL, false);
+      (*pexpr)->determine_type(&context);
+    }
   return TRAVERSE_CONTINUE;
 }
 
diff --git a/go/names.cc b/go/names.cc
index a721a36..1f0a545 100644
--- a/go/names.cc
+++ b/go/names.cc
@@ -975,7 +975,14 @@
     return "unsafe.Pointer..d";
 
   if (nt == NULL)
-    return "type.." + type->mangled_name(this);
+    {
+      // Sanity check: we should never generate a type descriptor for
+      // an unnamed primitive type.  For those we should always be
+      // using a named type, like "int".
+      go_assert(!type->is_basic_type());
+
+      return "type.." + type->mangled_name(this);
+    }
 
   std::string ret;
   Named_object* no = nt->named_object();