Skip to content

Commit

Permalink
writer: handle imports for slice params
Browse files Browse the repository at this point in the history
  • Loading branch information
enosi-rl committed Apr 17, 2022
1 parent ec925f3 commit da24f99
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/gtrace/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func (w *Writer) typeImports(dst []dep, t types.Type) []dep {
if p, ok := t.(*types.Pointer); ok {
return w.typeImports(dst, p.Elem())
}
if p, ok := t.(*types.Slice); ok {
return w.typeImports(dst, p.Elem())
}
n, ok := t.(*types.Named)
if !ok {
return dst
Expand Down
13 changes: 13 additions & 0 deletions test/test_imports_pointer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test

import "github.com/gobwas/gtrace/test/internal"

//go:generate gtrace -v

//gtrace:gen
//gtrace:set shortcut
// NOTE: must compile without unused imports error.
type TracePointer struct {
OnSomethingA func(Type)
OnSomethingB func(*internal.Type)
}
68 changes: 68 additions & 0 deletions test/test_imports_pointer_gtrace.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/test_imports_slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test

import "github.com/gobwas/gtrace/test/internal"

//go:generate gtrace -v

//gtrace:gen
//gtrace:set shortcut
// NOTE: must compile without unused imports error.
type TraceArray struct {
OnSomethingA func(Type)
OnSomethingB func([]internal.Type)
}
68 changes: 68 additions & 0 deletions test/test_imports_slice_gtrace.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da24f99

Please # to comment.