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

*types.TypeParam mishandling when using pointer type #577

Closed
londek opened this issue Sep 2, 2022 · 4 comments · Fixed by #580
Closed

*types.TypeParam mishandling when using pointer type #577

londek opened this issue Sep 2, 2022 · 4 comments · Fixed by #580
Assignees

Comments

@londek
Copy link

londek commented Sep 2, 2022

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.0.0-20220831134526-d0c6ccd63dd8

Build settings:
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
             vcs git
    vcs.revision d0c6ccd63dd8d090d45f8dff200f330f5d2b0860
        vcs.time 2022-08-31T13:45:26Z
    vcs.modified true

$ go version
go version devel go1.20-91ef076562 Thu Sep 1 02:24:14 2022 +0000 linux/amd64

Both freshly built from master in hope it changes anything - tried before 1.18.1 with official garble package and 1.19 with freshly built package

What environment are you running Garble on?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/londek/.cache/go-build"
GOENV="/home/londek/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/londek/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/londek/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/londek/golang-src"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/londek/golang-src/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-91ef076562 Thu Sep 1 02:24:14 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/londek/hey/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3436927412=/tmp/go-build -gno-record-gcc-switches"

What did you do?

It's a very specific, I would even say edge-case use of Garble. I've defined type with generic and underlying type being slice of the generic. I've created function which returns this type - the tricky part is that generic is a pointer type (it only errors with pointer, values work well).

Please take a look at my playground to ensure reproducibility
https://go.dev/play/p/wwNYKnXAiuv

What did you expect to see?

No error; Working program

What did you see instead?

panic: interface conversion: *types.TypeParam is not main.Container: missing method Elem

goroutine 1 [running]:
main.(*transformer).recordType(0xc0000a1c50, {0x738860, 0xc0001afb30?}, {0x738928?, 0xc0001c59b0?})
/home/londek/garble/main.go:1393 +0x338
main.(*transformer).recordType(0xc0000a1c50, {0x7388b0, 0xc0001afb70?}, {0x7388b0?, 0xc0001afae0?})
/home/londek/garble/main.go:1394 +0x385
main.(*transformer).recordType(0xc0000a1c50, {0x738838, 0xc0001c8e00?}, {0x0?, 0x0?})
/home/londek/garble/main.go:1408 +0x145
main.(*transformer).typecheck(0xc0000a1c50, {0xc0000ae800, 0x1, 0x1})
/home/londek/garble/main.go:1373 +0x5f7
main.transformCompile({0xc0000b4020?, 0x139?, 0xc000117e98?})
/home/londek/garble/main.go:731 +0x392
main.mainErr({0xc0000b4010, 0x11, 0x11})
/home/londek/garble/main.go:426 +0x6cd
main.main1()
/home/londek/garble/main.go:228 +0x16e
main.main()
/home/londek/garble/main.go:135 +0x19

@mvdan
Copy link
Member

mvdan commented Sep 3, 2022

Thanks for reporting this bug with a reproducer! Looking into it.

@mvdan mvdan self-assigned this Sep 3, 2022
mvdan added a commit to mvdan/garble-fork that referenced this issue Sep 6, 2022
I was wrongly assumed that, if `used` has an `Elem` method,
then `origin` must too. But it does not if it's a type parameter.

Add a test case too, which panicked before the fix.

Fixes burrowers#577.
@mvdan mvdan closed this as completed in #580 Sep 6, 2022
mvdan added a commit that referenced this issue Sep 6, 2022
I was wrongly assumed that, if `used` has an `Elem` method,
then `origin` must too. But it does not if it's a type parameter.

Add a test case too, which panicked before the fix.

Fixes #577.
@NHAS
Copy link

NHAS commented Sep 20, 2022

Howdy, is this going to be added in a release soon? (Sorry to ping a closed issue)

Just planning to use this in my project and would like to be able to use @latest for the install command :)

@mvdan
Copy link
Member

mvdan commented Sep 20, 2022

We will do a release soon, but given that there have just been two bug fixes so far and people can use master now, we're not in a terrible rush. See https://github.com/burrowers/garble/blob/master/CHANGELOG.md.

@NHAS
Copy link

NHAS commented Sep 20, 2022

Ah awesome! Not meaning to rush ya'll was just wondering about this (and being selfish with wanting to use it :P)

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

Successfully merging a pull request may close this issue.

3 participants