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

Conversion of a pointer type to source type #64032

Closed
gucio321 opened this issue Nov 9, 2023 · 2 comments
Closed

Conversion of a pointer type to source type #64032

gucio321 opened this issue Nov 9, 2023 · 2 comments

Comments

@gucio321
Copy link
Contributor

gucio321 commented Nov 9, 2023

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

$ go version
go version go1.21.3 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/me/.cache/go-build'
GOENV='/home/me/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/me/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/me/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1650394567=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I wrot a simple code:

package main

import "fmt"

type (
        foo int
        bar *foo
)

func main() {
        var y bar
        fmt.Printf("%T\n", y)
        fmt.Printf("%T\n", (*int)(y)) // <- Why this doesn't work?
        fmt.Printf("%T\n", (*int)((*foo)(y)))
}

What did you expect to see?

The code should compile

What did you see instead?

./main.go:13:28: cannot convert y (variable of type bar) to type *int
@Jorropo
Copy link
Member

Jorropo commented Nov 9, 2023

I'm pretty sure https://go.dev/doc/faq#convert_slice_with_same_underlying_type applies here even tho you are not using slices.


I feel this also applies https://github.com/golang/go/wiki/Questions

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions.

🙂

@gucio321
Copy link
Contributor Author

gucio321 commented Nov 9, 2023

I see, thanks for your answer. I tought it is a bug and should be fixed (as these are not slices)

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