for i, typ := range inferred {
if typ == nil || isParameterized(tparams, typ) {
obj := tparams[i].obj
- err.addf(pos, "cannot infer %s (%v)", obj.name, obj.pos)
+ err.addf(pos, "cannot infer %s (declared at %v)", obj.name, obj.pos)
return nil
}
}
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)
}
}
}
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
+}
for i, typ := range inferred {
if typ == nil || isParameterized(tparams, typ) {
obj := tparams[i].obj
- err.addf(posn, "cannot infer %s (%v)", obj.name, obj.pos)
+ err.addf(posn, "cannot infer %s (declared at %v)", obj.name, obj.pos)
return nil
}
}
--- /dev/null
+// errorcheck
+
+// Copyright 2024 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
+
+func f[S any, T any](T) {}
+func g() {
+ f(0) // ERROR "in call to f, cannot infer S \(declared at issue68292.go:9:8\)"
+}