func (o fmtOpTypeIdName) Format(s fmt.State, verb rune) { Op(o).format(s, verb, FTypeIdName) }
func (o Op) Format(s fmt.State, verb rune) { o.format(s, verb, FErr) }
-func (t *fmtTypeErr) Format(s fmt.State, verb rune) { typeFormat((*types.Type)(t), s, verb, FErr) }
-func (t *fmtTypeDbg) Format(s fmt.State, verb rune) { typeFormat((*types.Type)(t), s, verb, FDbg) }
-func (t *fmtTypeTypeId) Format(s fmt.State, verb rune) { typeFormat((*types.Type)(t), s, verb, FTypeId) }
+func (t *fmtTypeErr) Format(s fmt.State, verb rune) { typeFormat((*types.Type)(t), s, verb, FErr) }
+func (t *fmtTypeDbg) Format(s fmt.State, verb rune) { typeFormat((*types.Type)(t), s, verb, FDbg) }
+func (t *fmtTypeTypeId) Format(s fmt.State, verb rune) {
+ typeFormat((*types.Type)(t), s, verb, FTypeId)
+}
func (t *fmtTypeTypeIdName) Format(s fmt.State, verb rune) {
typeFormat((*types.Type)(t), s, verb, FTypeIdName)
}
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// testcase for issue #28082
+
+func foo() {}
+
+func main() {}
+
+func bar() {}
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// testcase for issue #28082
+
+func foo( ) {}
+
+func main( ) {}
+
+func bar() {}
p.print(x)
case *ast.FuncLit:
- p.expr(x.Type)
- p.funcBody(p.distanceFrom(x.Type.Pos()), blank, x.Body)
+ p.print(x.Type.Pos(), token.FUNC)
+ // See the comment in funcDecl about how the header size is computed.
+ startCol := p.out.Column - len("func")
+ p.signature(x.Type.Params, x.Type.Results)
+ p.funcBody(p.distanceFrom(x.Type.Pos(), startCol), blank, x.Body)
case *ast.ParenExpr:
if _, hasParens := x.X.(*ast.ParenExpr); hasParens {
p.block(b, 1)
}
-// distanceFrom returns the column difference between from and p.pos (the current
-// estimated position) if both are on the same line; if they are on different lines
-// (or unknown) the result is infinity.
-func (p *printer) distanceFrom(from token.Pos) int {
- if from.IsValid() && p.pos.IsValid() {
- if f := p.posFor(from); f.Line == p.pos.Line {
- return p.pos.Column - f.Column
- }
+// distanceFrom returns the column difference between p.out (the current output
+// position) and startOutCol. If the start position is on a different line from
+// the current position (or either is unknown), the result is infinity.
+func (p *printer) distanceFrom(startPos token.Pos, startOutCol int) int {
+ if startPos.IsValid() && p.pos.IsValid() && p.posFor(startPos).Line == p.pos.Line {
+ return p.out.Column - startOutCol
}
return infinity
}
func (p *printer) funcDecl(d *ast.FuncDecl) {
p.setComment(d.Doc)
p.print(d.Pos(), token.FUNC, blank)
+ // We have to save startCol only after emitting FUNC; otherwise it can be on a
+ // different line (all whitespace preceding the FUNC is emitted only when the
+ // FUNC is emitted).
+ startCol := p.out.Column - len("func ")
if d.Recv != nil {
p.parameters(d.Recv) // method: print receiver
p.print(blank)
}
p.expr(d.Name)
p.signature(d.Type.Params, d.Type.Results)
- p.funcBody(p.distanceFrom(d.Pos()), vtab, d.Body)
+ p.funcBody(p.distanceFrom(d.Pos(), startCol), vtab, d.Body)
}
func (p *printer) decl(decl ast.Decl) {
}
}
-func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) }
-func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) }
-func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexAnyTests) }
-func TestLastIndexAny(t *testing.T) { runIndexTests(t, LastIndexAny, "LastIndexAny", lastIndexAnyTests) }
+func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) }
+func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) }
+func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexAnyTests) }
+func TestLastIndexAny(t *testing.T) {
+ runIndexTests(t, LastIndexAny, "LastIndexAny", lastIndexAnyTests)
+}
func TestIndexByte(t *testing.T) {
for _, tt := range indexTests {