Skip to content

Commit

Permalink
compiler: Report unused variables initialized to function literals.
Browse files Browse the repository at this point in the history
Fixes golang/go#12317.

Change-Id: Ida147dbd6797b4a458c4d612a5198f4e7860a8f1
Reviewed-on: https://go-review.googlesource.com/13908
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
Chris Manghane authored and ianlancetaylor committed Aug 27, 2015
1 parent 9ae5835 commit 3aa2ea2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions go/gogo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3156,6 +3156,7 @@ Check_types_traverse::variable(Named_object* named_object)
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
Expand All @@ -3180,13 +3181,13 @@ Check_types_traverse::variable(Named_object* named_object)
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());
}
Expand Down

0 comments on commit 3aa2ea2

Please sign in to comment.