modfile: replace empty comments when adding indirect

When we add an "indirect" token to a line with an empty comment (only
whitespace after //), we should replace the comment text.

In CL 208273, we inserted "indirect;". The isIndirect predicate returns
false for "// indirect;" because there's only one word. When
modload.WriteGoMod is called multiple times (as it is in
'go mod tidy'), this caused us to write "// indirect; indirect".

Updates golang/go#35737

Change-Id: Ic2531a61ab15df7a0d4462ea3b1d25753d06d1d1
Run-TryBot: Jay Conrod <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Bryan C. Mills <>
2 files changed