You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I upgraded a project from 23a0d19 to 3d21d22 and am now having troubles converting a struct to an interface.
The exact problem stems from converting a struct with an embedded struct, wherein both structs have unique methods, to a typed interface. If only one of the structs has methods, the problem goes away.
Minimal reproducible code:
package main
import (
"github.com/cosmos72/gomacro/fast"
)
funcmain() {
interp:=fast.New()
src:=` type VEntity interface { A() int B() int } type BaseEntity struct { } func (e *BaseEntity) A() int { return 0 } type ExtendedEntity struct { BaseEntity } func (e *ExtendedEntity) B() int { return 1 } entity := &ExtendedEntity{} ventity := VEntity(entity) // <-- this line causes panic: runtime error: invalid memory address or nil pointer dereference `interp.Compile(src)
}
Thanks for spotting this, and more thanks for the bisection!
Commit c545040 is a bugfix, which replaces a complicated (and broken) workaround with a clean implementation.
But from the regression you found, it seems the bugfix is not fully correct.
Bug confirmed.
Interestingly enough, executing the same code at REPL does not trigger the bug.
I suspect some gomacro's implementation confusion between compile-time and runtime.
Commit 4d60a7f detects this bug, and replaces the generic panic message
panic: runtime error: invalid memory address or nil pointer dereference
with the more detailed
panic: repl.go:24:28: cannot convert from <*main.ExtendedEntity> to <main.VEntity>: internal error, method B of <*main.ExtendedEntity> has nil type!
(known bug under investigation, see https://github.com/cosmos72/gomacro/issues/139)
It's not a solution, but at least I've narrowed it down to a method type being (unexpectedly) nil.
I upgraded a project from 23a0d19 to 3d21d22 and am now having troubles converting a struct to an interface.
The exact problem stems from converting a struct with an embedded struct, wherein both structs have unique methods, to a typed interface. If only one of the structs has methods, the problem goes away.
Minimal reproducible code:
Error output:
The text was updated successfully, but these errors were encountered: