This patch by Chris Manghane fixes an oversight in the Go compiler
that caused it to fail to report unused variables initialized to
function literals.  This fixes https://golang.org/issue/12317 .
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 227284)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-9ae5835a010a55fba875103be5f4e61485a97099
+3aa2ea272e475010da8b480fc3095d0cd7254d12
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/gogo.cc
===================================================================
--- gcc/go/gofrontend/gogo.cc   (revision 227276)
+++ gcc/go/gofrontend/gogo.cc   (working copy)
@@ -3156,6 +3156,7 @@ Check_types_traverse::variable(Named_obj
            error_at(var->location(),
                     "incompatible type in initialization (%s)",
                     reason.c_str());
+          init = Expression::make_error(named_object->location());
          var->clear_init();
        }
       else if (init != NULL
@@ -3180,13 +3181,13 @@ Check_types_traverse::variable(Named_obj
                        no->message_name().c_str());
             }
         }
-      else if (!var->is_used()
-              && !var->is_global()
-              && !var->is_parameter()
-              && !var->is_receiver()
-              && !var->type()->is_error()
-              && (init == NULL || !init->is_error_expression())
-              && !Lex::is_invalid_identifier(named_object->name()))
+      if (!var->is_used()
+          && !var->is_global()
+          && !var->is_parameter()
+          && !var->is_receiver()
+          && !var->type()->is_error()
+          && (init == NULL || !init->is_error_expression())
+          && !Lex::is_invalid_identifier(named_object->name()))
        error_at(var->location(), "%qs declared and not used",
                 named_object->message_name().c_str());
     }

Reply via email to