pomack / thrift4go

Apache Thrift for the Go Language
129 stars 23 forks source link

Bad generated code -- double import section #59

Open cespare opened 11 years ago

cespare commented 11 years ago

Maybe I'm doing something wrong, but I'm getting generated Go code that has imports in the file after some code (which is illegal). I get this with my own thrift code, but also just with the tutorial.

$ ./thrift-0.9.0/compiler/cpp/thrift -r --gen go thrift-0.9.0/tutorial/tutorial.thrift
./gen-go//tutorial/Calculator.go:23:1: expected declaration, found 'import'
WARNING - Running 'gofmt -w ./gen-go//tutorial/Calculator.go' failed.
./gen-go//tutorial/ttypes.go:23:1: expected declaration, found 'import'
WARNING - Running 'gofmt -w ./gen-go//tutorial/ttypes.go' failed.

And when we look at gen-go/tutorial/Calculator.go:

// Comments elided
package tutorial;

import (
        "fmt"
        "math"
        "thrift"
)

func init() {
        var temporaryAndUnused int32 = math.MinInt32
        temporaryAndUnused++
}

import "shared"

type ICalculator interface {
  ...