• Dmitri Shuralyov's avatar
    go/printer: set prefix correctly when all comment lines blank · 928c83ff
    Dmitri Shuralyov authored
    In stripCommonPrefix, the prefix was correctly calculated in all cases,
    except one. That unhandled case is when there are more than 2 lines,
    but all lines are blank (other than the first and last lines,
    which contain /* and */ respectively).
    This change detects that case and correctly sets the prefix calculated
    from the last line. This is consistent with the (correct) behavior
    that happens when there's at least one non-blank line.
    That fixes issue #9751 that occurs for problematic input,
    where cmd/gofmt and go/source would insert extra indentation on
    every format operation. It also allows go/printer itself to print
    such parsed files in an expected way.
    
    Fixes #9751.
    
    Change-Id: Id3dfb945beb59ffad3705085a3c285fca30a5f87
    Reviewed-on: https://go-review.googlesource.com/3684
    
    Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
    928c83ff
printer.go 37 KB