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: unexported names can't be used in a library's generic function #39840

Closed
argusdusty opened this issue Jun 24, 2020 · 2 comments
Closed

Comments

@argusdusty
Copy link

@argusdusty argusdusty commented Jun 24, 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 unexportedFunc() {
	println("Hello, World!")
}

func ExportedFunc(type T)(t T) {
	unexportedFunc()
}

foo/foo.go2:

package main

import "foo/lib"

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

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

What did you expect to see?

Successful compilation.

What did you see instead?

.\foo.go2:7: undefined: unexportedFunc

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
 instantiatelibExportedFuncint(0)
//line foo.go2:7
}
//line foo.go2:6
func instantiatelibExportedFuncint(t (int)) {
	unexportedFunc()
}

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

@gopherbot gopherbot commented Jun 24, 2020

Change https://golang.org/cl/239709 mentions this issue: [dev.go2go] cmd/go2go: doc: instantiations can't refer to unexported names

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 24, 2020

Yes, that isn't going to work with the go2go tool, which is just for experimentation. There are a number of cases it can't handle, and that is one of them. This is only a deficiency of the go2go tool; any actual implementation of generics would not have this problem.

I just added a note to the go2go tool docs.

gopherbot pushed a commit that referenced this issue Jun 24, 2020
…names

For #39840

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