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: non-generic functions can't be used in a library's generic function #39842

Closed
argusdusty opened this issue Jun 25, 2020 · 3 comments
Closed

Comments

@argusdusty
Copy link

@argusdusty argusdusty commented Jun 25, 2020

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

C:\Users\argusdusty\Code\src\foo>go version
go version devel +2dce748bd8 Wed Jun 24 22:35:01 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

reproduces with 2dce748

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

go env Output
C:\Users\argusdusty\Code\src\foo>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\argusdusty\AppData\Local\go-build
set GOENV=C:\Users\argusdusty\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\argusdusty\Code\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\argusdusty\Code
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Gosrc
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Gosrc\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ARGUSD~1\AppData\Local\Temp\go-build612910630=/tmp/go-build -gno-record-gcc-switches

What did you do?

foo/lib/lib.go2:

package lib

func NonGenericFunc() {
	println("Hello, World!")
}

func GenericFunc(type T)(t T) {
	NonGenericFunc()
}

foo/foo.go2:

package main

import "foo/lib"

func main() {
	lib.GenericFunc(0)
}

C:\Users\argusdusty\Code\src\foo>go tool go2go build

What did you expect to see?

Successful compilation.

foo/foo.go:

// Code generated by go2go; DO NOT EDIT.


//line foo.go2:1
package main

//line foo.go2:1
import "foo/lib"

//line foo.go2:5
func main() {
//line foo.go2:5
 instantiatelibGenericFuncint(0)
//line foo.go2:7
}
//line foo.go2:7
func instantiatelibGenericFuncint(t (int)) {
	lib.NonGenericFunc()
}

//line :1
type Importableint
//line :1
type _ lib.Importable

What did you see instead?

.\foo.go2:9: undefined: NonGenericFunc

foo.go:

// Code generated by go2go; DO NOT EDIT.


//line foo.go2:1
package main

//line foo.go2:1
import "foo/lib"

//line foo.go2:5
func main() {
//line foo.go2:5
 instantiatelibGenericFuncint(0)
//line foo.go2:7
}
//line foo.go2:7
func instantiatelibGenericFuncint(t (int)) {
	NonGenericFunc()
}

//line :1
type Importableint
//line :1
type _ lib.Importable
@argusdusty
Copy link
Author

@argusdusty argusdusty commented Jun 25, 2020

Closing per updated doc comments that indicate this is an unsupported case.

@argusdusty argusdusty closed this Jun 25, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 25, 2020

Change https://golang.org/cl/239711 mentions this issue: [dev.go2go] go/go2go: add package qualifier when needed

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 25, 2020

Actually, this case should work. It's the case where we refer to an unexported name that doesn't work.

I just committed a fix and this now works on the dev.go2go branch. Thanks for reporting it.

gopherbot pushed a commit that referenced this issue Jun 25, 2020
Fixes #39842

Change-Id: I5046f1bdd7dbc6d1e17cf3835826933aaadf1581
Reviewed-on: https://go-review.googlesource.com/c/go/+/239711
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.