Skip to content

Commit 3227501

Browse files
committed
go/types: use error_.errorf for reporting related error information
Use error_.errorf for reporting related error information rather than inlining the "\n\t". This aligns go/types with types2 in cases where the related information has no position information. In other cases, go/types needs to report a "continuation error" (starting with '\t') so that users can access multiple error positions. Change-Id: Ica98466596c374e0c1e502e7227c8d8c803b4c22 Reviewed-on: https://go-review.googlesource.com/c/go/+/400825 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
1 parent 65d7345 commit 3227501

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/go/types/assignments.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package types
99
import (
1010
"fmt"
1111
"go/ast"
12+
"go/token"
1213
"strings"
1314
)
1415

@@ -339,11 +340,10 @@ func (check *Checker) initVars(lhs []*Var, origRHS []ast.Expr, returnStmt ast.St
339340
} else if len(rhs) > 0 {
340341
at = rhs[len(rhs)-1].expr // report at last value
341342
}
342-
check.errorf(at, _WrongResultCount, "%s return values\n\thave %s\n\twant %s",
343-
qualifier,
344-
check.typesSummary(operandTypes(rhs), false),
345-
check.typesSummary(varTypes(lhs), false),
346-
)
343+
err := newErrorf(at, _WrongResultCount, "%s return values", qualifier)
344+
err.errorf(token.NoPos, "have %s", check.typesSummary(operandTypes(rhs), false))
345+
err.errorf(token.NoPos, "want %s", check.typesSummary(varTypes(lhs), false))
346+
check.report(err)
347347
return
348348
}
349349
if compilerErrorMessages {

src/go/types/call.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,10 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
368368
if sig.params != nil {
369369
params = sig.params.vars
370370
}
371-
check.errorf(at, _WrongArgCount, "%s arguments in call to %s\n\thave %s\n\twant %s",
372-
qualifier, call.Fun,
373-
check.typesSummary(operandTypes(args), false),
374-
check.typesSummary(varTypes(params), sig.variadic),
375-
)
371+
err := newErrorf(at, _WrongArgCount, "%s arguments in call to %s", qualifier, call.Fun)
372+
err.errorf(token.NoPos, "have %s", check.typesSummary(operandTypes(args), false))
373+
err.errorf(token.NoPos, "want %s", check.typesSummary(varTypes(params), sig.variadic))
374+
check.report(err)
376375
return
377376
}
378377

src/go/types/conversions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package types
88

99
import (
1010
"go/constant"
11+
"go/token"
1112
"unicode"
1213
)
1314

@@ -74,7 +75,9 @@ func (check *Checker) conversion(x *operand, T Type) {
7475
if compilerErrorMessages {
7576
if cause != "" {
7677
// Add colon at end of line if we have a following cause.
77-
check.errorf(x, _InvalidConversion, "cannot convert %s to type %s:\n\t%s", x, T, cause)
78+
err := newErrorf(x, _InvalidConversion, "cannot convert %s to type %s:", x, T)
79+
err.errorf(token.NoPos, cause)
80+
check.report(err)
7881
} else {
7982
check.errorf(x, _InvalidConversion, "cannot convert %s to type %s", x, T)
8083
}

0 commit comments

Comments
 (0)