Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LastPossum opened this issue Jun 21, 2020 · 2 comments
Closed

Comments

@LastPossum
Copy link

@LastPossum LastPossum commented Jun 21, 2020

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.

@cagedmantis cagedmantis changed the title cmd/go2go using types from packages with slashes in names causes syntax error cmd/go2go: using types from packages with slashes in names causes syntax error Jun 22, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 22, 2020

Change https://golang.org/cl/239381 mentions this issue: [dev.go2go] go/go2go: use package name, not package path

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 22, 2020

Thanks for the test case. This is now fixed on the dev.go2go branch.

gopherbot pushed a commit that referenced this issue Jun 22, 2020
types.TypeString defaults to using the package path for references to names.
Provide our own types.Qualifier that uses just the package name,
since that is what the translated code has to use.

Fixes #39744

Change-Id: Icde289b2ed0fdd9b0a9aae6aae4557a8951d25a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/239381
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.