Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing nil as a function parameter? #277

Closed
saward opened this issue Oct 18, 2021 · 1 comment
Closed

Passing nil as a function parameter? #277

saward opened this issue Oct 18, 2021 · 1 comment

Comments

@saward
Copy link

saward commented Oct 18, 2021

Hi,

What's the correct way for me to call a function, passing nil to one or more parameters? This example throws an error, when I'd expect it to work:

package main

import (
	"fmt"

	pongo2 "github.com/flosch/pongo2/v4"
)

func main() {
	tpl, err := pongo2.FromString("Nil func: {{ nilFunc(nil) }}")
	if err != nil {
		panic(err)
	}
	nilFunc := func(in interface{}) string {
		return fmt.Sprintf("%T", in)
	}
	out, err := tpl.Execute(pongo2.Context{"nilFunc": nilFunc})
	if err != nil {
		panic(err)
	}
	fmt.Println(out)
}

Error:

% go run main.go
panic: [Error (where: execution) in <string> | Line 1 Col 14 near 'nilFunc'] Calling a function using an invalid parameter

goroutine 1 [running]:
main.main()
        /Users/mark/temp/pt/main.go:19 +0x167
exit status 2
@flosch flosch closed this as completed in aec36e7 Jun 24, 2022
@flosch
Copy link
Owner

flosch commented Jun 24, 2022

You can now pass nil to function aguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants