Skip to content

cmd/go2go: using types from packages with slashes in names causes syntax error #39744

@LastPossum

Description

@LastPossum

What version of Go are you using (go version)?

$ go version
built from https://github.com/golang/go/commit/0a030888da0f33ef75111f079258ab78b1c3eb64 

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/goroot/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build083452119=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I ran this code https://go2goplay.golang.org/p/2-0wCuAqvau

package main import ( "fmt" "net/http" ) type Option(type T) struct { v T err error } func (o *Option(T)) Value() (T, error) { return o.v, o.err } func Try(type T)(f func() (T, error)) Option(T) { v, err := f() return Option(T){ v: v, err: err, } } func Success(type T)(v T) Option(T) { return Option(T){ v: v, } } func Map(type T1, T2)(opt Option(T1), f func(T1) T2) Option(T2) { v1, err := opt.Value() if err != nil { return Option(T2){err: err} } return Option(T2){v: f(v1)} } func FMap(type T1, T2)(opt Option(T1), f func(T1) (T2, error)) Option(T2) { v1, err := opt.Value() if err != nil { return Option(T2){err: err} } v2, err := f(v1) return Option(T2){v: v2, err: err} } func main() { client := &http.Client{} optReq := Try(func()(*http.Request, error){return http.NewRequest("GET", "http://golang.org", nil)}) optResp := FMap(optReq, client.Do) resp, err := optResp.Value() if err!=nil{ fmt.Println(err) return } fmt.Print(resp) }

What did you expect to see?

Not sure, but not the syntax error

What did you see instead?

If I use the playground, I get the panic. If I use version, built from the latest dev.go2go code, I get following:

./option.go2:18: syntax error: unexpected /, expecting )
./option.go2:40: syntax error: unexpected /, expecting )
./option.go2:10: syntax error: unexpected /, expecting )
./option.go2:14: syntax error: unexpected /, expecting )
./option.go2:10: syntax error: unexpected /, expecting )
./option.go2:14: syntax error: unexpected /, expecting )
/goroot/bin/go [run option.go] failed: exit status 2

P.S. Please consider adding method type parameters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions