Skip to content

reflect: generate runtime [circle refrence] types similar to compile time. #70339

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

Closed
Neightly opened this issue Nov 14, 2024 · 2 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@Neightly
Copy link

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

$ go version
go version go1.23.2 windows/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=D:\GOPATH\GOBIN
set GOCACHE=D:\GOPATH\GOCACHE
set GOENV=C:\Users\PC\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\GOPATH\GOMODCACHE
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\GOPATH
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\DEVELOPMENT\GO
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=D:\DEVELOPMENT\GO\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.2
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\PC\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=zig cc -target x86_64-windows-gnu
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=x86_64-windows-gnu -I . -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\PC\AppData\Local\Temp\go-build581384153=/tmp/go-build -gno-record-gcc-switches

What did you do?

https://go.dev/play/p/-Xxe-Pmh0lG

package main

import "reflect"

// we can write static codes.

type A struct {
	ID      uint64
	Related []B
}

type B struct {
	Name    string
	Related *A
}

type C struct {
	Data uintptr
	*C
}

// how can we write dynamic codes?
func ExampleDynamic() {
	A := reflect.StructOf([]reflect.StructField{
		{Name: "ID", Type: reflect.TypeFor[uint64]()},
		{
			Name: "Related",
			Type: reflect.SliceOf(nil), // how can we do here?
		},
	})
	B := reflect.StructOf([]reflect.StructField{
		{Name: "Name", Type: reflect.TypeFor[string]()},
		{
			Name: "Related",
			Type: reflect.PointerTo(nil), // how can we do here?
		},
	})
	C := reflect.StructOf([]reflect.StructField{
		{Name: "Data", Type: reflect.TypeFor[uintptr]()},
		{
			Name:      "C",
			Type:      reflect.PointerTo(nil), // how can we do here?
			Anonymous: true,
		},
	})
	_, _, _ = A, B, C
}

statically, types are in package scope, calculation can be lazy.
dynamically, type in StructField muse be immediate.

What did you expect to see?

we can write runtime types similar to compile time types.

What did you see instead?

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 14, 2024
@seankhliao
Copy link
Member

Duplicate of #39717

@seankhliao seankhliao marked this as a duplicate of #39717 Nov 14, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

4 participants