compiler: don't use sink as parameter in method expression thunk

Also fix a couple of cases where the error led to a later compiler crash.

Test case is https://go.dev/cl/414336.

Fixes golang/go#52871

Change-Id: If3a9ecfca20e782c2e827a176f24923c62c48ae8
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/414354
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 135dae0..f59f61d 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -1426,7 +1426,12 @@
   Gogo* gogo = context->gogo();
   if (this->bvar_ == NULL)
     {
-      go_assert(this->type_ != NULL && !this->type_->is_sink_type());
+      if (this->type_ == NULL || this->type_->is_sink_type())
+	{
+	  go_assert(saw_errors());
+	  return gogo->backend()->error_expression();
+	}
+
       Named_object* fn = context->function();
       go_assert(fn != NULL);
       Bfunction* fn_ctx = fn->func_value()->get_or_make_decl(gogo, fn);
@@ -15235,7 +15240,7 @@
 	   p != method_parameters->end();
 	   ++p, ++i)
 	{
-	  if (!p->name().empty())
+	  if (!p->name().empty() && !Gogo::is_sink_name(p->name()))
 	    parameters->push_back(*p);
 	  else
 	    {
diff --git a/go/types.cc b/go/types.cc
index 39aea76..e82be68 100644
--- a/go/types.cc
+++ b/go/types.cc
@@ -4654,8 +4654,11 @@
   { return false; }
 
   Btype*
-  do_get_backend(Gogo*)
-  { go_unreachable(); }
+  do_get_backend(Gogo* gogo)
+  {
+    go_assert(saw_errors());
+    return gogo->backend()->error_type();
+  }
 
   Expression*
   do_type_descriptor(Gogo*, Named_type*)