pkujhd / goloader

load and run golang code at runtime.
Apache License 2.0
497 stars 58 forks source link

内置接口类型 error 无法解析 #96

Closed Sgmwei closed 5 months ago

Sgmwei commented 5 months ago

darwin/arm64 (macbook m1 air) golang1.21.8

type (
    IDo interface {
        Do() error
    }
    Struct1 struct{}
)

func (Struct1) Do() error {
    fmt.Print("DO SOMETHING\n")
    return nil
}

func NewStructX() IDo {
    return Struct1{}
}

加载上述测试文件将报错unresolve external:type:error

mwat56 commented 5 months ago

On 9 April 2024 11:32:02 CEST, Sgmwei @.***> wrote:

darwin/arm64 (macbook m1 air) golang1.21.8


type (
  IDo interface {
      Do() error
  }
  Struct1 struct{}
)

func (Struct1) Do() error {

The receiver needs a name, not only a type.

fmt.Print("DO SOMETHING\n") return nil }

func NewStructX() IDo { return Struct1{} }


加载上述测试文件将报错`unresolve external:type:error`

--
Liebe Grüße 🙋🏼‍♂️ Matthias --
/"\ \ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL X - AGAINST M$ ATTACHMENTS / \ http://www.asciiribbon.org/

Sgmwei commented 5 months ago

not only a type.

Tks for pointing out my grammar is not complete, but this does not affect the occurrence of errors.

by the way, goloader 's version is github.com/pkujhd/goloader v0.0.0-20240302083706-9af26f1bc5bc, and the occurrence happend at addSymbolMap (/github.com/pkujhd/goloader@v0.0.0-20240302083706-9af26f1bc5bc/ld.go:378) when i debug symPtr can't find the key 'type:error', which in linker.SymMap need to use.

eh-steve commented 5 months ago

Seems to work on my fork… https://github.com/eh-steve/goloader/commit/d53913edf861c452828b98a17f9e1f5976c61505

pkujhd commented 5 months ago

Seems to work on my fork… eh-steve@d53913e

When registering a type without a package name, registerType() will resolve its name. but when this type is an interface, it get a different name.  type:error is an internal interface without a package name. registerType get a wrong name("Interface { Error() string }")  @eh-steve Steve's fork works because this version will attempt to handle undefined symbols. It copys type:error from runtime.a again.

Sgmwei commented 5 months ago

Seems to work on my fork… eh-steve@d53913e

When registering a type without a package name, registerType() will resolve its name. but when this type is an interface, it get a different name.  type:error is an internal interface without a package name. registerType get a wrong name("Interface { Error() string }")  @eh-steve Steve's fork works because this version will attempt to handle undefined symbols. It copys type:error from runtime.a again.

So what's your suggest if I want to continue using your branch ?😯