Unexpected assignment

This works as expected

{{ $i := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }}  --> 3

This also works as expected

{{ $x := 0 }}
{{ $i := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }}  --> 3

But if you reverse the order of the first two lines:

{{ $i := 0 }}
{{ $x := 0 }}
{{ range $i = slice 1 2 3 }}
{{ end }}
{{ $i }}  --> [1 2 3]  (this should be 3, not a slice)

I didn’t expect this result. Are my expectations unreasonable?

Tested with v0.105.0 and v0.54.0… same results.

https://github.com/golang/go/issues/56490

https://github.com/gohugoio/hugo/issues/10411