Patchwork [gccgo] Only warn about no new variables when using :=

login
register
mail settings
Submitter Ian Taylor
Date Aug. 31, 2010, 11:15 p.m.
Message ID <mcry6bmbcgy.fsf@google.com>
Download mbox | patch
Permalink /patch/63328/
State New
Headers show

Comments

Ian Taylor - Aug. 31, 2010, 11:15 p.m.
The compiler should only warn about not creating any new variables when
using :=.  Otherwise the warning makes no sense.  This can happen when
using the special sink variable "_".  Committed to gccgo branch.

Ian

Patch

diff -r 08d6b67dc3e6 go/parse.cc
--- a/go/parse.cc	Tue Aug 31 16:06:34 2010 -0700
+++ b/go/parse.cc	Tue Aug 31 16:14:12 2010 -0700
@@ -1543,7 +1543,7 @@ 
       this->init_var(*pv, type, init, is_coloneq, false, &any_new);
     }
 
-  if (!any_new)
+  if (is_coloneq && !any_new)
     error_at(location, "variables redeclared but no variable is new");
 
   return true;
@@ -1584,7 +1584,7 @@ 
 				    &any_new);
   Expression* present_var = Expression::make_var_reference(no, location);
 
-  if (!any_new)
+  if (is_coloneq && !any_new)
     error_at(location, "variables redeclared but no variable is new");
 
   Statement* s = Statement::make_tuple_map_assignment(val_var, present_var,
@@ -1633,7 +1633,7 @@ 
 				    &any_new);
   Expression* received_var = Expression::make_var_reference(no, location);
 
-  if (!any_new)
+  if (is_coloneq && !any_new)
     error_at(location, "variables redeclared but no variable is new");
 
   Statement* s = Statement::make_tuple_receive_assignment(val_var,
@@ -1690,7 +1690,7 @@ 
 							     texpr, t,
 							     location);
 
-  if (!any_new)
+  if (is_coloneq && !any_new)
     error_at(location, "variables redeclared but no variable is new");
 
   if (!this->gogo_->in_global_scope())