mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/types2: change inference error message
Changes the type inference error message so that the position is proceeded by a space. cmd/go rewrites the output of gc to replace absolute paths at the beginning of lines and those proceeded by a space or a tab to relative paths. Updates testdir to do the same post processing on the output of tests as cmd/go. Fixes #68292 Change-Id: Ie109b51143e68f6e7ab4cd19064110db0e609a7e Reviewed-on: https://go-review.googlesource.com/c/go/+/603097 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
206df8e7ad
commit
0253c0f4ac
4 changed files with 35 additions and 3 deletions
|
|
@ -1212,7 +1212,7 @@ func (t test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err
|
|||
for i := range out {
|
||||
for j := 0; j < len(fullshort); j += 2 {
|
||||
full, short := fullshort[j], fullshort[j+1]
|
||||
out[i] = strings.Replace(out[i], full, short, -1)
|
||||
out[i] = replacePrefix(out[i], full, short)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1962,3 +1962,23 @@ func splitQuoted(s string) (r []string, err error) {
|
|||
}
|
||||
return args, err
|
||||
}
|
||||
|
||||
// replacePrefix is like strings.ReplaceAll, but only replaces instances of old
|
||||
// that are preceded by ' ', '\t', or appear at the beginning of a line.
|
||||
//
|
||||
// This does the same kind of filename string replacement as cmd/go.
|
||||
// Pilfered from src/cmd/go/internal/work/shell.go .
|
||||
func replacePrefix(s, old, new string) string {
|
||||
n := strings.Count(s, old)
|
||||
if n == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
s = strings.ReplaceAll(s, " "+old, " "+new)
|
||||
s = strings.ReplaceAll(s, "\n"+old, "\n"+new)
|
||||
s = strings.ReplaceAll(s, "\n\t"+old, "\n\t"+new)
|
||||
if strings.HasPrefix(s, old) {
|
||||
s = new + s[len(old):]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue