Skip to content

Commit

Permalink
fix(check): support functions declared in package
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jan 29, 2025
1 parent 00ea966 commit 50ec6a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion check.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func CheckTemplates(wd string, log *log.Logger, config RoutesFileConfiguration)
dataVarPkg = receiver.Obj().Pkg()
methodObj, _, _ := types.LookupFieldOrMethod(receiver, true, dataVarPkg, name)
if methodObj == nil {
return fmt.Errorf("failed to generate method %s", t.fun.Name)
o, ok := packageScopeFunc(receiver.Obj().Pkg(), t.fun)
if !ok {
return fmt.Errorf("failed to generate method %s", t.fun.Name)
}
methodObj = o
}
sig := methodObj.Type().(*types.Signature)
if sig.Results().Len() == 0 {
Expand Down
8 changes: 5 additions & 3 deletions cmd/muxt/testdata/generate/function_in_package_simple.txtar
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
muxt generate

cat template_routes.go
stdout '// muxt version: \(devel\)'

exec go test -cover

muxt check --receiver-type=Server

-- template.gohtml --
{{define "GET / Function(ctx)" }}{{.}}{{end}}

Expand All @@ -27,6 +26,9 @@ var formHTML embed.FS
var templates = template.Must(template.ParseFS(formHTML, "*"))

func Function(ctx context.Context) int { return 32 }

type Server struct{}

-- template_test.go --
package server

Expand Down

0 comments on commit 50ec6a3

Please sign in to comment.