How to link or relocation unexported method of generics type in golang?

153 views
Skip to first unread message

彭锟(vvvvainman)

unread,
Feb 20, 2023, 1:50:14 PM2/20/23
to golang-nuts

for example, I have file "pkg/A/internal/A.go" that has code like shown below

```golang

package internal 

type AS[T any] struct { } 

func (s *AS[T]) helloLink() string { 

  return "hello" 

}

```


And I have another one file "pkg/B/B.go"

```golang
package B 
import ( _ "unsafe" _ "pkg/A/internel" ) 
type BS[T any] struct { } 
//go:linkname pkgHello pkg/A/internel.(*AS[T]).helloLink 
func pkgHello[T any](s *BS[T]) string

```

when I try to run this code, it tells that " parameterized function is missing function body"

  1. I have set asm.s file in package B
  2. It works without generics declaration
  3. Ignore import path shown in code, it should be right

Ian Lance Taylor

unread,
Feb 21, 2023, 12:49:29 AM2/21/23
to 彭锟(vvvvainman), golang-nuts
This is not supported. Sorry.

Ian

Emrah Mutlu

unread,
Feb 23, 2023, 12:03:21 PM2/23/23
to golang-nuts
thanks

21 Şubat 2023 Salı tarihinde saat 07:49:29 UTC+2 itibarıyla Ian Lance Taylor şunları yazdı:
Reply all
Reply to author
Forward
0 new messages