Commit d2fc5d68 authored by Rob Pike's avatar Rob Pike

Change type of Printf's args to ... interface{}

R=rsc
CC=golang-dev
https://golang.org/cl/197043
parent 1f11ece6
......@@ -76,7 +76,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
}
// Die with an error message.
func fatal(msg string, args ...) {
func fatal(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args)
os.Exit(2)
}
......@@ -84,7 +84,7 @@ func fatal(msg string, args ...) {
var nerrors int
var noPos token.Position
func error(pos token.Position, msg string, args ...) {
func error(pos token.Position, msg string, args ...interface{}) {
nerrors++
if pos.IsValid() {
fmt.Fprintf(os.Stderr, "%s: ", pos)
......
......@@ -3097,7 +3097,7 @@ func create(s string, m int) *bufio.Writer {
//
// write out error comment
//
func error(s string, v ...) {
func error(s string, v ...interface{}) {
nerrors++
fmt.Fprintf(stderr, s, v)
fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
......
......@@ -282,7 +282,7 @@ func (t *thread) ptraceDetach() os.Error {
var logLock sync.Mutex
func (t *thread) logTrace(format string, args ...) {
func (t *thread) logTrace(format string, args ...interface{}) {
if !trace {
return
}
......@@ -301,7 +301,7 @@ func (t *thread) logTrace(format string, args ...) {
fmt.Fprint(os.Stderr, "\n")
}
func (t *thread) warn(format string, args ...) {
func (t *thread) warn(format string, args ...interface{}) {
logLock.Lock()
defer logLock.Unlock()
fmt.Fprintf(os.Stderr, "Thread %d: WARNING ", t.tid)
......@@ -309,7 +309,7 @@ func (t *thread) warn(format string, args ...) {
fmt.Fprint(os.Stderr, "\n")
}
func (p *process) logTrace(format string, args ...) {
func (p *process) logTrace(format string, args ...interface{}) {
if !trace {
return
}
......
......@@ -27,7 +27,7 @@ type compiler struct {
silentErrors int
}
func (a *compiler) diagAt(pos positioned, format string, args ...) {
func (a *compiler) diagAt(pos positioned, format string, args ...interface{}) {
a.errors.Error(pos.Pos(), fmt.Sprintf(format, args))
a.numErrors++
}
......
......@@ -58,7 +58,7 @@ func (a *exprInfo) newExpr(t Type, desc string) *expr {
return &expr{exprInfo: a, t: t, desc: desc}
}
func (a *exprInfo) diag(format string, args ...) {
func (a *exprInfo) diag(format string, args ...interface{}) {
a.diagAt(&a.pos, format, args)
}
......
......@@ -27,7 +27,7 @@ type stmtCompiler struct {
stmtLabel *label
}
func (a *stmtCompiler) diag(format string, args ...) {
func (a *stmtCompiler) diag(format string, args ...interface{}) {
a.diagAt(&a.pos, format, args)
}
......
......@@ -91,7 +91,7 @@ func (p *parser) init(filename string, src []byte, mode uint) {
// ----------------------------------------------------------------------------
// Parsing support
func (p *parser) printTrace(a ...) {
func (p *parser) printTrace(a ...interface{}) {
const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
const n = uint(len(dots))
......
This diff is collapsed.
......@@ -93,7 +93,7 @@ func (p *parser) init(filename string, src []byte, scope *ast.Scope, mode uint)
// ----------------------------------------------------------------------------
// Parsing support
func (p *parser) printTrace(a ...) {
func (p *parser) printTrace(a ...interface{}) {
const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " +
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
const n = uint(len(dots))
......
......@@ -101,7 +101,7 @@ func (p *printer) init(output io.Writer, cfg *Config) {
}
func (p *printer) internalError(msg ...) {
func (p *printer) internalError(msg ...interface{}) {
if debug {
fmt.Print(p.pos.String() + ": ")
fmt.Println(msg)
......
......@@ -149,31 +149,33 @@ func (l *Logger) Output(calldepth int, s string) os.Error {
}
// Logf is analogous to Printf() for a Logger.
func (l *Logger) Logf(format string, v ...) { l.Output(2, fmt.Sprintf(format, v)) }
func (l *Logger) Logf(format string, v ...interface{}) {
l.Output(2, fmt.Sprintf(format, v))
}
// Log is analogous to Print() for a Logger.
func (l *Logger) Log(v ...) { l.Output(2, fmt.Sprintln(v)) }
func (l *Logger) Log(v ...interface{}) { l.Output(2, fmt.Sprintln(v)) }
// Stdout is a helper function for easy logging to stdout. It is analogous to Print().
func Stdout(v ...) { stdout.Output(2, fmt.Sprint(v)) }
func Stdout(v ...interface{}) { stdout.Output(2, fmt.Sprint(v)) }
// Stderr is a helper function for easy logging to stderr. It is analogous to Fprint(os.Stderr).
func Stderr(v ...) { stderr.Output(2, fmt.Sprintln(v)) }
func Stderr(v ...interface{}) { stderr.Output(2, fmt.Sprintln(v)) }
// Stdoutf is a helper functions for easy formatted logging to stdout. It is analogous to Printf().
func Stdoutf(format string, v ...) { stdout.Output(2, fmt.Sprintf(format, v)) }
func Stdoutf(format string, v ...interface{}) { stdout.Output(2, fmt.Sprintf(format, v)) }
// Stderrf is a helper function for easy formatted logging to stderr. It is analogous to Fprintf(os.Stderr).
func Stderrf(format string, v ...) { stderr.Output(2, fmt.Sprintf(format, v)) }
func Stderrf(format string, v ...interface{}) { stderr.Output(2, fmt.Sprintf(format, v)) }
// Exit is equivalent to Stderr() followed by a call to os.Exit(1).
func Exit(v ...) { exit.Output(2, fmt.Sprintln(v)) }
func Exit(v ...interface{}) { exit.Output(2, fmt.Sprintln(v)) }
// Exitf is equivalent to Stderrf() followed by a call to os.Exit(1).
func Exitf(format string, v ...) { exit.Output(2, fmt.Sprintf(format, v)) }
func Exitf(format string, v ...interface{}) { exit.Output(2, fmt.Sprintf(format, v)) }
// Crash is equivalent to Stderr() followed by a call to panic().
func Crash(v ...) { crash.Output(2, fmt.Sprintln(v)) }
func Crash(v ...interface{}) { crash.Output(2, fmt.Sprintln(v)) }
// Crashf is equivalent to Stderrf() followed by a call to panic().
func Crashf(format string, v ...) { crash.Output(2, fmt.Sprintf(format, v)) }
func Crashf(format string, v ...interface{}) { crash.Output(2, fmt.Sprintf(format, v)) }
......@@ -187,14 +187,14 @@ func New(fmap FormatterMap) *Template {
}
// Report error and stop executing. The line number must be provided explicitly.
func (t *Template) execError(st *state, line int, err string, args ...) {
func (t *Template) execError(st *state, line int, err string, args ...interface{}) {
st.errors <- &Error{line, fmt.Sprintf(err, args)}
runtime.Goexit()
}
// Report error, save in Template to terminate parsing.
// The line number comes from the template state.
func (t *Template) parseError(err string, args ...) {
func (t *Template) parseError(err string, args ...interface{}) {
t.error = &Error{t.linenum, fmt.Sprintf(err, args)}
}
......
......@@ -89,34 +89,34 @@ func (t *T) FailNow() {
// Log formats its arguments using default formatting, analogous to Print(),
// and records the text in the error log.
func (t *T) Log(args ...) { t.errors += "\t" + tabify(fmt.Sprintln(args)) }
func (t *T) Log(args ...interface{}) { t.errors += "\t" + tabify(fmt.Sprintln(args)) }
// Log formats its arguments according to the format, analogous to Printf(),
// and records the text in the error log.
func (t *T) Logf(format string, args ...) {
func (t *T) Logf(format string, args ...interface{}) {
t.errors += "\t" + tabify(fmt.Sprintf(format, args))
}
// Error is equivalent to Log() followed by Fail().
func (t *T) Error(args ...) {
func (t *T) Error(args ...interface{}) {
t.Log(args)
t.Fail()
}
// Errorf is equivalent to Logf() followed by Fail().
func (t *T) Errorf(format string, args ...) {
func (t *T) Errorf(format string, args ...interface{}) {
t.Logf(format, args)
t.Fail()
}
// Fatal is equivalent to Log() followed by FailNow().
func (t *T) Fatal(args ...) {
func (t *T) Fatal(args ...interface{}) {
t.Log(args)
t.FailNow()
}
// Fatalf is equivalent to Logf() followed by FailNow().
func (t *T) Fatalf(format string, args ...) {
func (t *T) Fatalf(format string, args ...interface{}) {
t.Logf(format, args)
t.FailNow()
}
......
......@@ -92,7 +92,7 @@ func eliminate_digit(d int64) {
bignum.Iscale(numer, 10)
}
func printf(s string, arg ...) {
func printf(s string, arg ...interface{}) {
if !*silent {
fmt.Printf(s, arg)
}
......
......@@ -10,9 +10,7 @@ import "fmt"
var result string
func addInt(i int) {
result += fmt.Sprint(i)
}
func addInt(i int) { result += fmt.Sprint(i) }
func test1helper() {
for i := 0; i < 10; i++ {
......@@ -21,16 +19,14 @@ func test1helper() {
}
func test1() {
result = "";
test1helper();
result = ""
test1helper()
if result != "9876543210" {
fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result);
fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result)
}
}
func addDotDotDot(v ...) {
result += fmt.Sprint(v)
}
func addDotDotDot(v ...interface{}) { result += fmt.Sprint(v) }
func test2helper() {
for i := 0; i < 10; i++ {
......@@ -39,14 +35,14 @@ func test2helper() {
}
func test2() {
result = "";
test2helper();
result = ""
test2helper()
if result != "9876543210" {
fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result);
fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result)
}
}
func main() {
test1();
test2();
test1()
test2()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment