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

Type aliases points to the underlying type not the root one, this cause issues where the autogenerated go package does not build if it links to internal packages. #348

Open
Jorropo opened this issue Feb 24, 2024 · 4 comments

Comments

@Jorropo
Copy link
Contributor

Jorropo commented Feb 24, 2024

I have code like this:

.
├── a.go
├── b
│   ├── b.go
│   └── internal
│       └── internal.go
└── go.mod
// a.go
package a

import "a/b"

type A = b.B
// b.go
package b

import "a/b/internal"

type B = internal.I
// internal.go
package internal

import "strconv"

type I uint

func (i I) String() string { return strconv.FormatUint(uint64(i), 10) }

gopy pkg a then creates a folder a/a and tries to import a/b/internal which does not work because it's not allowed to import an internal package.

My real world usecase is some existing librairy with type alias chains going through multiple modules.

I think this could be solved with the GODEBUG=gotypesalias=1 https://pkg.go.dev/go/types#Alias but I'm not familiar with the gopy codebase.

@rcoreilly
Copy link
Member

Your PR fixed this right?

@rcoreilly
Copy link
Member

also internal is now excluded automatically

@Jorropo
Copy link
Contributor Author

Jorropo commented Apr 23, 2024

I retried with cdad836, it does not, my PR fixed some panic but there are more

--- building package ---
gopy pkg --dynamic-link=true github.com/libp2p/go-libp2p
goimports -w go-libp2p.go
go build -mod=mod -buildmode=c-shared -o go-libp2p_go.so .
cmd had error: exit status 1  output:
go: finding module for package github.com/go-python/gopy/gopyh
go: downloading github.com/go-python/gopy v0.4.9
go: found github.com/go-python/gopy/gopyh in github.com/go-python/gopy v0.4.9
package github.com/libp2p/go-libp2p/go-libp2p
	go-libp2p.go:108:2: use of internal package github.com/quic-go/quic-go/internal/handshake not allowed

2024/04/23 03:29:53 error dispatching command: exit status 1

with GODEBUG=gotypesalias=1:

panic: not yet supported: github.com/libp2p/go-libp2p.Config (*types.TypeName)

goroutine 1 [running]:
github.com/go-python/gopy/bind.(*Package).process(0xc029fe0900)
	/home/hugo/k/gopy/bind/package.go:394 +0x20fe
github.com/go-python/gopy/bind.NewPackage(0xc029dc9980, 0xc02a0225a0)
	/home/hugo/k/gopy/bind/package.go:68 +0x27c
main.parsePackage(0xc000253080)
	/home/hugo/k/gopy/gen.go:159 +0x276
main.buildPkgRecurse({0xc000018780, 0x20}, {0x7ffef0d2490c, 0x1b}, {0x7ffef0d2490c, 0x1b}, 0xc029fa7c68, {0x0, 0x0})
	/home/hugo/k/gopy/cmd_pkg.go:162 +0x2b6
main.gopyRunCmdPkg(0xc000172d20, {0xc0000140f0, 0x1, 0x74f198?})
	/home/hugo/k/gopy/cmd_pkg.go:132 +0xd19
github.com/gonuts/commander.(*Command).Dispatch(0xc000172d20, {0xc0000140e0, 0x2, 0x2})
	/home/hugo/go/pkg/mod/github.com/gonuts/commander@v0.1.0/commands.go:209 +0x170
github.com/gonuts/commander.(*Command).Dispatch(0xc000172f00, {0xc0000140d0, 0x3, 0x3})
	/home/hugo/go/pkg/mod/github.com/gonuts/commander@v0.1.0/commands.go:175 +0x22f
main.run({0xc0000140d0, 0x3, 0x3})
	/home/hugo/k/gopy/main.go:62 +0x25b
main.main()
	/home/hugo/k/gopy/main.go:70 +0x49

@Jorropo
Copy link
Contributor Author

Jorropo commented Apr 23, 2024

My particular repro:

cd /tmp
git clone --depth 1 https://github.com/libp2p/go-libp2p
cd go-libp2p

GODEBUG=gotypespackage=1 gopy pkg github.com/libp2p/go-libp2p
# or original internal pointing issue:
gopy pkg github.com/libp2p/go-libp2p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants