golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.68k stars 17.49k forks source link

cmd\go2go: non-generic functions can't be used in a library's generic function #39842

Closed argusdusty closed 4 years ago

argusdusty commented 4 years ago

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
 instantiate୦lib୦GenericFunc୦int(0)
//line foo.go2:7
}
//line foo.go2:7
func instantiate୦lib୦GenericFunc୦int(t (int)) {
    lib.NonGenericFunc()
}

//line :1
type Importable୦ int
//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
 instantiate୦lib୦GenericFunc୦int(0)
//line foo.go2:7
}
//line foo.go2:7
func instantiate୦lib୦GenericFunc୦int(t (int)) {
    NonGenericFunc()
}

//line :1
type Importable୦ int
//line :1
type _ lib.Importable୦
argusdusty commented 4 years ago

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

gopherbot commented 4 years ago

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

ianlancetaylor commented 4 years ago

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.