can't import fsm package
SuperGod opened this issue · 4 comments
I install gomacro from master branch:
go install github.com/cosmos72/gomacro@master
and then run gomacro cmd:
gomacro> import "github.com/looplab/fsm"
gomacro> f := fsm.NewFSM("empty", fsm.Events{}, map[string]fsm.Callback{})
reflect: Call using map[string]xreflect.Forward as type map[string]fsm.Callback
but got error:
reflect: Call using map[string]xreflect.Forward as type map[string]fsm.Callback
fsm.NewFSM is defined as:
type Callback func(*Event)
......
func NewFSM(initial string, events []EventDesc, callbacks map[string]Callback) *FSM {
......
}
Thank for spotting this :)
I'll investigate this bug
I've just rechecked this issue, and it seems to be working now (using Go toolchain <= 1.19, see issue #146).
Can you confirm?
I re-checked after (hopefully) fixing issue #146, and now import "github.com/looplab/fsm"
fails with:
gomacro> import "github.com/looplab/fsm"
// debug: running "go get github.com/looplab/fsm" ...
go: added github.com/looplab/fsm v1.0.1
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_28645/import_1" ...
Converter.Type(): unsupported types.Type: *types.TypeParam
This is because gomacro does not yet know about go/types.TypeParam
which represents a type parameter for a Go generic.
I'll add support for them as soon as I have time.
Commit 68a1200 skips generics when importing third-party packages,
because importing generics is not yet supported.
Now import "github.com/looplab/fsm"
works:
gomacro> import "github.com/looplab/fsm"
// debug: running "go get github.com/looplab/fsm" ...
go: added github.com/looplab/fsm v1.0.1
// debug: running "go mod tidy" ...
// debug: compiling plugin "/home/max/go/src/gomacro.imports/gomacro_pid_19060/import_1" ...
// warning: skipping import of func sync.OnceValue[T any](f func() T) func() T: importing generic functions or types is not supported yet
// warning: skipping import of func sync.OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2): importing generic functions or types is not supported yet
gomacro> :env fsm
// ----- "github.com/looplab/fsm" binds -----
FlowChart = flowChart // fsm.MermaidDiagramType
GRAPHVIZ = graphviz // fsm.VisualizeType
MERMAID = mermaid // fsm.VisualizeType
MermaidFlowChart = mermaid-flow-chart // fsm.VisualizeType
MermaidStateDiagram = mermaid-state-diagram // fsm.VisualizeType
NewFSM = 0x7f8eb4375380 // func(string, []fsm.EventDesc, map[string]fsm.Callback) *fsm.FSM
StateDiagram = stateDiagram // fsm.MermaidDiagramType
Visualize = 0x7f8eb43782e0 // func(*fsm.FSM) string
VisualizeForMermaidWithGraphType = 0x7f8eb43788c0 // func(*fsm.FSM, fsm.MermaidDiagramType) (string, error)
VisualizeWithType = 0x7f8eb4379300 // func(*fsm.FSM, fsm.VisualizeType) (string, error)
// ----- "github.com/looplab/fsm" types -----
AsyncError = fsm.AsyncError // struct
Callback = fsm.Callback // func
Callbacks = fsm.Callbacks // map
CanceledError = fsm.CanceledError // struct
Event = fsm.Event // struct
EventDesc = fsm.EventDesc // struct
Events = fsm.Events // slice
FSM = fsm.FSM // struct
InTransitionError = fsm.InTransitionError // struct
InternalError = fsm.InternalError // struct
InvalidEventError = fsm.InvalidEventError // struct
MermaidDiagramType = fsm.MermaidDiagramType // string
NoTransitionError = fsm.NoTransitionError // struct
NotInTransitionError = fsm.NotInTransitionError // struct
UnknownEventError = fsm.UnknownEventError // struct
VisualizeType = fsm.VisualizeType // string