]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: don't print ()'s around function-typed results (not needed anymore)
authorRobert Griesemer <gri@golang.org>
Wed, 24 Feb 2010 21:24:37 +0000 (13:24 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 24 Feb 2010 21:24:37 +0000 (13:24 -0800)
- add extra test cases to go/printer tests
- apply gofmt to src and misc

R=rsc
CC=golang-dev
https://golang.org/cl/223041

src/pkg/exp/eval/expr.go
src/pkg/exp/eval/expr1.go
src/pkg/exp/eval/stmt.go
src/pkg/exp/iterable/iterable.go
src/pkg/go/printer/nodes.go
src/pkg/go/printer/testdata/declarations.golden
src/pkg/go/printer/testdata/declarations.input
src/pkg/reflect/all_test.go
src/pkg/template/template_test.go

index 94714943c692a54aae403ded70b5c51b25b7871f..f875bb0052b17108c8249c38e6621fc5f6f71580 100644 (file)
@@ -303,7 +303,7 @@ func (a *assignCompiler) allowMapForms(nls int) {
 // a function that expects an l-value and the frame in which to
 // evaluate the RHS expressions.  The l-value must have exactly the
 // type given by lt.  Returns nil if type checking fails.
-func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
+func (a *assignCompiler) compile(b *block, lt Type) func(Value, *Thread) {
        lmt, isMT := lt.(*MultiType)
        rmt, isUnpack := a.rmt, a.isUnpack
 
@@ -446,7 +446,7 @@ func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
 // compileAssign compiles an assignment operation without the full
 // generality of an assignCompiler.  See assignCompiler for a
 // description of the arguments.
-func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) (func(Value, *Thread)) {
+func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) func(Value, *Thread) {
        ac, ok := a.checkAssign(pos, rs, errOp, errPosName)
        if !ok {
                return nil
@@ -836,8 +836,8 @@ func (a *exprInfo) compileSelectorExpr(v *expr, name string) *expr {
        // TODO(austin) Now that the expression compiler works on
        // semantic values instead of AST's, there should be a much
        // better way of doing this.
-       var find func(Type, int, string) (func(*expr) *expr)
-       find = func(t Type, depth int, pathName string) (func(*expr) *expr) {
+       var find func(Type, int, string) func(*expr) *expr
+       find = func(t Type, depth int, pathName string) func(*expr) *expr {
                // Don't bother looking if we've found something shallower
                if bestDepth != -1 && bestDepth < depth {
                        return nil
index a77e40fb0a9b29b55611199af8a2bcf49d7b3f15..28da8eea1b6ef12a1da8999f7bef4665a1f3cf43 100644 (file)
@@ -12,40 +12,36 @@ import (
  * "As" functions.  These retrieve evaluator functions from an
  * expr, panicking if the requested evaluator has the wrong type.
  */
-func (a *expr) asBool() (func(*Thread) bool) { return a.eval.(func(*Thread) bool) }
-func (a *expr) asUint() (func(*Thread) uint64) {
-       return a.eval.(func(*Thread) uint64)
-}
-func (a *expr) asInt() (func(*Thread) int64) { return a.eval.(func(*Thread) int64) }
-func (a *expr) asIdealInt() (func() *bignum.Integer) {
+func (a *expr) asBool() func(*Thread) bool   { return a.eval.(func(*Thread) bool) }
+func (a *expr) asUint() func(*Thread) uint64 { return a.eval.(func(*Thread) uint64) }
+func (a *expr) asInt() func(*Thread) int64   { return a.eval.(func(*Thread) int64) }
+func (a *expr) asIdealInt() func() *bignum.Integer {
        return a.eval.(func() *bignum.Integer)
 }
-func (a *expr) asFloat() (func(*Thread) float64) {
+func (a *expr) asFloat() func(*Thread) float64 {
        return a.eval.(func(*Thread) float64)
 }
-func (a *expr) asIdealFloat() (func() *bignum.Rational) {
+func (a *expr) asIdealFloat() func() *bignum.Rational {
        return a.eval.(func() *bignum.Rational)
 }
-func (a *expr) asString() (func(*Thread) string) {
+func (a *expr) asString() func(*Thread) string {
        return a.eval.(func(*Thread) string)
 }
-func (a *expr) asArray() (func(*Thread) ArrayValue) {
+func (a *expr) asArray() func(*Thread) ArrayValue {
        return a.eval.(func(*Thread) ArrayValue)
 }
-func (a *expr) asStruct() (func(*Thread) StructValue) {
+func (a *expr) asStruct() func(*Thread) StructValue {
        return a.eval.(func(*Thread) StructValue)
 }
-func (a *expr) asPtr() (func(*Thread) Value) { return a.eval.(func(*Thread) Value) }
-func (a *expr) asFunc() (func(*Thread) Func) { return a.eval.(func(*Thread) Func) }
-func (a *expr) asSlice() (func(*Thread) Slice) {
-       return a.eval.(func(*Thread) Slice)
-}
-func (a *expr) asMap() (func(*Thread) Map) { return a.eval.(func(*Thread) Map) }
-func (a *expr) asMulti() (func(*Thread) []Value) {
+func (a *expr) asPtr() func(*Thread) Value   { return a.eval.(func(*Thread) Value) }
+func (a *expr) asFunc() func(*Thread) Func   { return a.eval.(func(*Thread) Func) }
+func (a *expr) asSlice() func(*Thread) Slice { return a.eval.(func(*Thread) Slice) }
+func (a *expr) asMap() func(*Thread) Map     { return a.eval.(func(*Thread) Map) }
+func (a *expr) asMulti() func(*Thread) []Value {
        return a.eval.(func(*Thread) []Value)
 }
 
-func (a *expr) asInterface() (func(*Thread) interface{}) {
+func (a *expr) asInterface() func(*Thread) interface{} {
        switch sf := a.eval.(type) {
        case func(t *Thread) bool:
                return func(t *Thread) interface{} { return sf(t) }
@@ -1871,7 +1867,7 @@ func (a *expr) genBinOpNeq(l, r *expr) {
        }
 }
 
-func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
+func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
        switch lt.lit().(type) {
        case *boolType:
                rf := r.asBool()
index 758e479f89d1a0a8e2917ac8a189e59b5784bb0a..75b934b3d846c648b7c9704740c6e0490d106fc8 100644 (file)
@@ -1226,7 +1226,7 @@ func (a *blockCompiler) exit() { a.block.exit() }
  * Function compiler
  */
 
-func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) (func(*Thread) Func) {
+func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) func(*Thread) Func {
        // Create body scope
        //
        // The scope of a parameter or result is the body of the
index b1ae0e90fe64bf4b686fc436fa68da9305c89235..416a70836ed87f5f8b966ac3e714654a03baa2fa 100644 (file)
@@ -18,7 +18,7 @@ type Iterable interface {
        Iter() <-chan interface{}
 }
 
-func not(f func(interface{}) bool) (func(interface{}) bool) {
+func not(f func(interface{}) bool) func(interface{}) bool {
        return func(e interface{}) bool { return !f(e) }
 }
 
index dd6b1db6b23a9de3446b3877270777ded4af2542..6096751bd92f817b5c79e389e6a3e553545ac8ee 100644 (file)
@@ -241,19 +241,13 @@ func (p *printer) signature(params, result []*ast.Field, multiLine *bool) {
        p.parameters(params, multiLine)
        if result != nil {
                p.print(blank)
-
                if len(result) == 1 && result[0].Names == nil {
-                       // single anonymous result; no ()'s unless it's a function type
-                       f := result[0]
-                       if _, isFtyp := f.Type.(*ast.FuncType); !isFtyp {
-                               p.expr(f.Type, multiLine)
-                               return
-                       }
+                       // single anonymous result; no ()'s
+                       p.expr(result[0].Type, multiLine)
+                       return
                }
-
                p.parameters(result, multiLine)
        }
-       return
 }
 
 
index 9998103cfedf8bdeb649323228fe9c6c8d11e64d..b15e52ad64905bb32ff5d87f1e64d9641d4f2aeb 100644 (file)
@@ -471,6 +471,13 @@ func _() {
 }
 
 
+// formatting of function results
+func _() func()                                {}
+func _() func(int)                     { return nil }
+func _() func(int) int                 { return nil }
+func _() func(int) func(int) func()    { return nil }
+
+
 // formatting of consecutive single-line functions
 func _()       {}
 func _()       {}
index fd80cb626ced9a61b5dc544d53909a5095eaf926..1d1dc45f0c6bc53854eb09890df75d9cb7a511e8 100644 (file)
@@ -468,6 +468,13 @@ func _() {
 }
 
 
+// formatting of function results
+func _() func() {}
+func _() func(int) { return nil }
+func _() func(int) int { return nil }
+func _() func(int) func(int) func() { return nil }
+
+
 // formatting of consecutive single-line functions
 func _() {}
 func _() {}
index 221ca06dfefe7d1055581f3a0156ca4399264a7b..67bfe9eaf0b2e989a5302d0f613e7964452c64f1 100644 (file)
@@ -146,7 +146,7 @@ var typeTests = []pair{
        },
        pair{struct {
                x (interface {
-                       a(func(func(int) int) (func(func(int)) int))
+                       a(func(func(int) int) func(func(int)) int)
                        b()
                })
        }{},
index fe279a4d16fcd7796c94b22cbc4a38dc42709f0e..460a3a4b1eba5f3cf67c65a6a72746d2d52cd16c 100644 (file)
@@ -72,7 +72,7 @@ func plus1(v interface{}) string {
        return fmt.Sprint(i + 1)
 }
 
-func writer(f func(interface{}) string) (func(io.Writer, interface{}, string)) {
+func writer(f func(interface{}) string) func(io.Writer, interface{}, string) {
        return func(w io.Writer, v interface{}, format string) {
                io.WriteString(w, f(v))
        }