open2b/scriggo

Invalid swapping of elements in slice within a global slice

Opened this issue · 1 comments

Description

The swapping of the first and the second elements of a slice, which is assigned to a field of a struct of a (global) slice element, generates an invalid behavior.

How to reproduce

Add this test to test/misc/templates_test.go:

"https://github.com/open2b/scriggo/issues/945": {
	sources: fstest.Files{
		"index.txt": `
		{%%
			for item in items {
				item.Options[0], item.Options[1] = item.Options[1], item.Options[0]
				show item.Options[0].Name, ",", item.Options[1].Name
			}
		%%}
		`,
	},
	main: native.Package{
		Name: "main",
		Declarations: native.Declarations{
			"items": &[]struct {
				Options []struct {
					Name string
				}
			}{
				{Options: []struct{ Name string }{
					{Name: "first-option"},
					{Name: "second-option"},
				}},
			},
		},
	},
	expectedOut: "\nsecond-option,first-option\t\t\t",
},

@maisola-work this is the issue you encountered.