What's the BUG in the flag package?

88 views
Skip to first unread message

Matt Mueller

unread,
Mar 24, 2021, 6:25:15 PM3/24/21
to golang-nuts
I noticed a lonely BUG comment without an explanation in the flag package: https://github.com/golang/go/blob/master/src/flag/flag.go#L955

I did a quick `git blame` and it goes all the way back to the initial commit: https://github.com/golang/go/commit/ac0dd5ae525db0d057e94c03c3f506bc30afae31.

Any ideas what the bug could be? Maybe this can be removed and I should open a PR?

Thanks!
Matt

Jan Mercl

unread,
Mar 24, 2021, 6:30:45 PM3/24/21
to Matt Mueller, golang-nuts
On Wed, Mar 24, 2021 at 11:25 PM Matt Mueller <mattm...@gmail.com> wrote:

> I noticed a lonely BUG comment without an explanation in the flag package: https://github.com/golang/go/blob/master/src/flag/flag.go#L955

Looking at the code it seems to me that the comment is saying the
_client_ code has a bug in that it defines the same flag more than
once.

Ian Lance Taylor

unread,
Mar 24, 2021, 11:38:30 PM3/24/21
to Jan Mercl, Matt Mueller, golang-nuts
That could be, but BUG usually indicates something that should be
changed in the Go code.

In this case the original (and pretty much still current) code is

m := flags.formal;
flag, alreadythere = m[name]; // BUG

I bet that there was a bug in the compiler back in 2008 such that

flag, alreadythere = flag.formal[name];

didn't work, and the BUG refers to introducing a local variable that
is only used once.

If someone wants to send a CL removing the comment and removing the
local variable m that would be fine.

Thanks.

Ian
Reply all
Reply to author
Forward
0 new messages